Put std::string backing store in partition alloc Use is low compared to stringstream, but fix one occurrence. Change-Id: I2be7db4c9f4a55a91f6e4fda991712215998b6c1 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/89192 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/stl_util.h b/core/fxcrt/stl_util.h index d4ffde0..7b76f5e 100644 --- a/core/fxcrt/stl_util.h +++ b/core/fxcrt/stl_util.h
@@ -47,6 +47,10 @@ return std::vector<T, A>(safe_size.ValueOrDie()); } +// String that uses partition alloc for backing store. +using string = + std::basic_string<char, std::char_traits<char>, FxStringAllocator<char>>; + // String stream that uses PartitionAlloc for backing store. using ostringstream = std:: basic_ostringstream<char, std::char_traits<char>, FxStringAllocator<char>>;
diff --git a/core/fxcrt/stl_util_unittest.cpp b/core/fxcrt/stl_util_unittest.cpp index 33b80f2..ab291a3 100644 --- a/core/fxcrt/stl_util_unittest.cpp +++ b/core/fxcrt/stl_util_unittest.cpp
@@ -6,6 +6,19 @@ #include "testing/gtest/include/gtest/gtest.h" +TEST(STLUtil, string) { + fxcrt::string str; + str += '2'; + str += '2'; + str += "C is "; + str += '7'; + str += '1'; + str += '.'; + str += '6'; + str += "F"; + EXPECT_STREQ("22C is 71.6F", str.c_str()); +} + TEST(STLUtil, OStringStream) { fxcrt::ostringstream str; str << 22 << "C is " << 71.6f << "F";
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp index 39b3b82..dce96c4 100644 --- a/fxjs/cjs_publicmethods.cpp +++ b/fxjs/cjs_publicmethods.cpp
@@ -21,6 +21,7 @@ #include "core/fpdfdoc/cpdf_formcontrol.h" #include "core/fpdfdoc/cpdf_interactiveform.h" #include "core/fxcrt/fx_extension.h" +#include "core/fxcrt/stl_util.h" #include "core/fxge/cfx_color.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_interactiveform.h" @@ -118,12 +119,12 @@ // Make sure the number of precision characters will fit. iDec = std::min(iDec, std::numeric_limits<double>::digits10); - std::stringstream ss; + fxcrt::ostringstream ss; ss << std::fixed << std::setprecision(iDec) << dValue; - std::string value = ss.str(); + fxcrt::string value = ss.str(); size_t pos = value.find('.'); *iDec2 = pdfium::base::checked_cast<int>( - pos == std::string::npos ? value.size() : pos); + pos == fxcrt::string::npos ? value.size() : pos); return ByteString(value.c_str()); } #endif