Replace fxcrt::SmallBuffer with absl::InlinedVector Same reasoning as crbug.com/1465736. Change-Id: I7aab5d5641998bdf8a1e536a03a77d3311c38dff Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/112532 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/DEPS b/DEPS index 92b561b..871bf1c 100644 --- a/DEPS +++ b/DEPS
@@ -477,6 +477,7 @@ # explicitly here. '-absl', '-third_party/abseil-cpp', + '+third_party/abseil-cpp/absl/container/inlined_vector.h', '+third_party/abseil-cpp/absl/types/optional.h', '+third_party/abseil-cpp/absl/types/variant.h', ]
diff --git a/core/fpdfapi/page/cpdf_sampledfunc.cpp b/core/fpdfapi/page/cpdf_sampledfunc.cpp index 1dd9a5b..6ccc874 100644 --- a/core/fpdfapi/page/cpdf_sampledfunc.cpp +++ b/core/fpdfapi/page/cpdf_sampledfunc.cpp
@@ -14,8 +14,9 @@ #include "core/fpdfapi/parser/cpdf_stream.h" #include "core/fpdfapi/parser/cpdf_stream_acc.h" #include "core/fxcrt/cfx_bitstream.h" +#include "core/fxcrt/fx_memory_wrappers.h" #include "core/fxcrt/fx_safe_types.h" -#include "core/fxcrt/small_buffer.h" +#include "third_party/abseil-cpp/absl/container/inlined_vector.h" namespace { @@ -103,8 +104,10 @@ bool CPDF_SampledFunc::v_Call(pdfium::span<const float> inputs, pdfium::span<float> results) const { int pos = 0; - fxcrt::SmallBuffer<float, 16> encoded_input_buf(m_nInputs); - fxcrt::SmallBuffer<uint32_t, 32> int_buf(m_nInputs * 2); + absl::InlinedVector<float, 16, FxAllocAllocator<float>> encoded_input_buf( + m_nInputs); + absl::InlinedVector<uint32_t, 32, FxAllocAllocator<uint32_t>> int_buf( + m_nInputs * 2); float* encoded_input = encoded_input_buf.data(); uint32_t* index = int_buf.data(); uint32_t* blocksize = index + m_nInputs;
diff --git a/core/fxcrt/BUILD.gn b/core/fxcrt/BUILD.gn index 9e80bc6..1b3f6e4 100644 --- a/core/fxcrt/BUILD.gn +++ b/core/fxcrt/BUILD.gn
@@ -74,7 +74,6 @@ "retain_ptr.h", "scoped_set_insertion.h", "shared_copy_on_write.h", - "small_buffer.h", "span_util.h", "stl_util.h", "string_data_template.cpp", @@ -218,7 +217,6 @@ "retain_ptr_unittest.cpp", "scoped_set_insertion_unittest.cpp", "shared_copy_on_write_unittest.cpp", - "small_buffer_unittest.cpp", "span_util_unittest.cpp", "string_pool_template_unittest.cpp", "tree_node_unittest.cpp",
diff --git a/core/fxcrt/small_buffer.h b/core/fxcrt/small_buffer.h deleted file mode 100644 index a0fd5c2..0000000 --- a/core/fxcrt/small_buffer.h +++ /dev/null
@@ -1,49 +0,0 @@ -// Copyright 2017 The PDFium Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef CORE_FXCRT_SMALL_BUFFER_H_ -#define CORE_FXCRT_SMALL_BUFFER_H_ - -#include <string.h> - -#include <array> -#include <memory> - -#include "core/fxcrt/fx_memory_wrappers.h" - -namespace fxcrt { - -template <class T, size_t FixedSize> -class SmallBuffer { - public: - explicit SmallBuffer(size_t actual_size) : m_pSize(actual_size) { - if (actual_size > FixedSize) { - m_pDynamicData.reset(FX_Alloc(T, actual_size)); - return; - } - if (actual_size) - memset(m_FixedData.data(), 0, sizeof(T) * actual_size); - } - size_t size() const { return m_pSize; } - T* data() { - return m_pDynamicData ? m_pDynamicData.get() : m_FixedData.data(); - } - T* begin() { return data(); } - T* end() { return begin() + size(); } - - // Callers shouldn't need to know these details. - T* fixed_for_test() { return m_FixedData.data(); } - T* dynamic_for_test() { return m_pDynamicData.get(); } - - private: - const size_t m_pSize; - std::unique_ptr<T, FxFreeDeleter> m_pDynamicData; - std::array<T, FixedSize> m_FixedData; -}; - -} // namespace fxcrt - -#endif // CORE_FXCRT_SMALL_BUFFER_H_
diff --git a/core/fxcrt/small_buffer_unittest.cpp b/core/fxcrt/small_buffer_unittest.cpp deleted file mode 100644 index cbf4bdf..0000000 --- a/core/fxcrt/small_buffer_unittest.cpp +++ /dev/null
@@ -1,56 +0,0 @@ -// Copyright 2022 The PDFium Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "core/fxcrt/small_buffer.h" - -#include <algorithm> - -#include "testing/gtest/include/gtest/gtest.h" - -namespace fxcrt { - -TEST(SmallBuffer, Empty) { - SmallBuffer<int, 4> buffer(0); - EXPECT_EQ(buffer.data(), buffer.fixed_for_test()); - EXPECT_EQ(buffer.begin(), buffer.end()); -} - -TEST(SmallBuffer, NoFixed) { - SmallBuffer<int, 0> buffer(4); - EXPECT_EQ(buffer.data(), buffer.dynamic_for_test()); - std::fill(buffer.begin(), buffer.end(), 42); - int* ptr = buffer.data(); - EXPECT_EQ(42, ptr[0]); - EXPECT_EQ(42, ptr[1]); - EXPECT_EQ(42, ptr[2]); - EXPECT_EQ(42, ptr[3]); -} - -TEST(SmallBuffer, NoFixedEmpty) { - SmallBuffer<int, 0> buffer(0); - EXPECT_EQ(buffer.data(), buffer.fixed_for_test()); - EXPECT_EQ(buffer.begin(), buffer.end()); -} - -TEST(SmallBuffer, Fixed) { - SmallBuffer<int, 4> buffer(2); - EXPECT_EQ(buffer.data(), buffer.fixed_for_test()); - std::fill(buffer.begin(), buffer.end(), 42); - int* ptr = buffer.data(); - EXPECT_EQ(42, ptr[0]); - EXPECT_EQ(42, ptr[1]); -} - -TEST(SmallBuffer, Dynamic) { - SmallBuffer<int, 2> buffer(4); - EXPECT_EQ(buffer.data(), buffer.dynamic_for_test()); - std::fill(buffer.begin(), buffer.end(), 42); - int* ptr = buffer.data(); - EXPECT_EQ(42, ptr[0]); - EXPECT_EQ(42, ptr[1]); - EXPECT_EQ(42, ptr[2]); - EXPECT_EQ(42, ptr[3]); -} - -} // namespace fxcrt