Skip to content

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

Merged
aleks-f merged 2 commits intopocoproject:develfrom
Fabio3rs:devel
Jan 24, 2023
Merged

Remove unnecessary dup. of std::string in NumberParser::tryParseFloat#3864
aleks-f merged 2 commits intopocoproject:develfrom
Fabio3rs:devel

Conversation

@Fabio3rs
Copy link
Copy Markdown
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
Copy Markdown
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.

2 participants