Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary dup. of std::string in NumberParser::tryParseFloat #3864

Merged
merged 2 commits into from Jan 24, 2023

Conversation

Fabio3rs
Copy link
Contributor

@Fabio3rs Fabio3rs commented Nov 8, 2022

NumberParser::tryParseFloat is calling this overload:
bool strToDouble(const std::string& str, double& result, char decSep, char thSep, const char* inf, const char* nan)

Since it accepts a const std::string& str,, calling with s.c_str() will create a temporary std::string to call strToDouble


Maybe a possible patch for strToDouble would be change the strToDouble to receive a string by value without const ref and remove the std::string tmp from the code, thisway can avoid some possible multiple duplications when calling with a char* or similar.

bool strToDouble(std::string str, double& result, char decSep, char thSep, const char* inf, const char* nan)
{
	if (str.empty()) return false;

	using namespace double_conversion;

	trimInPlace(str);
	removeInPlace(str, thSep);
	replaceInPlace(str, decSep, '.');
	removeInPlace(str, 'f');
	result = strToDouble(str.c_str(), inf, nan);
	return !FPEnvironment::isInfinite(result) &&
		!FPEnvironment::isNaN(result);
}

@Fabio3rs
Copy link
Contributor Author

It seems that the test failures are the testDynamicStructEmptyString that is related with another issue.

@aleks-f aleks-f added this to the Release 1.13.0 milestone Jan 24, 2023
@aleks-f aleks-f merged commit c693b0b into pocoproject:devel Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants