Pass WideString by const-ref to ApplyNamedOperation().
Avoid c_str() calls in callers, and use EqualsASCIINoCase() to avoid
storing some wide literals.
Change-Id: Iea98afe2de4c06dee309959b79622816e21ba770
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/86853
Auto-Submit: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp
index d724f2e..fa93ed3 100644
--- a/fxjs/cjs_publicmethods.cpp
+++ b/fxjs/cjs_publicmethods.cpp
@@ -210,18 +210,18 @@
str->Replace(L",", L".");
}
-absl::optional<double> ApplyNamedOperation(const wchar_t* sFunction,
+absl::optional<double> ApplyNamedOperation(const WideString& wsFunction,
double dValue1,
double dValue2) {
- if (FXSYS_wcsicmp(sFunction, L"AVG") == 0 ||
- FXSYS_wcsicmp(sFunction, L"SUM") == 0) {
+ if (wsFunction.EqualsASCIINoCase("AVG") ||
+ wsFunction.EqualsASCIINoCase("SUM")) {
return dValue1 + dValue2;
}
- if (FXSYS_wcsicmp(sFunction, L"PRD") == 0)
+ if (wsFunction.EqualsASCIINoCase("PRD"))
return dValue1 * dValue2;
- if (FXSYS_wcsicmp(sFunction, L"MIN") == 0)
+ if (wsFunction.EqualsASCIINoCase("MIN"))
return std::min(dValue1, dValue2);
- if (FXSYS_wcsicmp(sFunction, L"MAX") == 0)
+ if (wsFunction.EqualsASCIINoCase("MAX"))
return std::max(dValue1, dValue2);
return absl::nullopt;
}
@@ -1253,8 +1253,7 @@
if (isnan(arg1) || isnan(arg2))
return CJS_Result::Failure(JSMessage::kValueError);
- absl::optional<double> result =
- ApplyNamedOperation(sFunction.c_str(), arg1, arg2);
+ absl::optional<double> result = ApplyNamedOperation(sFunction, arg1, arg2);
if (!result.has_value())
return CJS_Result::Failure(JSMessage::kValueError);
@@ -1354,7 +1353,7 @@
dValue = dTemp;
}
absl::optional<double> dResult =
- ApplyNamedOperation(sFunction.c_str(), dValue, dTemp);
+ ApplyNamedOperation(sFunction, dValue, dTemp);
if (!dResult.has_value())
return CJS_Result::Failure(JSMessage::kValueError);