Add an internal-only helper StringAppendAndOverwrite() similar to

StringResizeAndOverwrite() but optimized for repeated appends, using
exponential growth to ensure amortized complexity of increasing
a string size by a small amount is O(1).

Use this function to replace STLStringResizeUninitializedAmortized()

PiperOrigin-RevId: 825100704
Change-Id: Ife64b13301bc4288d68154b7c496f57aaad4b6a4
This commit is contained in:
Derek Mauro
2025-10-28 10:25:36 -07:00
committed by Copybara-Service
parent 2487de0742
commit f81f1b1d08
9 changed files with 337 additions and 96 deletions

View File

@@ -100,6 +100,7 @@ cc_library(
"string_view.h",
],
deps = [
":append_and_overwrite",
":charset",
":internal",
":resize_and_overwrite",
@@ -170,6 +171,32 @@ cc_test(
],
)
cc_library(
name = "append_and_overwrite",
hdrs = ["internal/append_and_overwrite.h"],
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
visibility = ["//visibility:private"],
deps = [
":resize_and_overwrite",
"//absl/base:config",
"//absl/base:core_headers",
],
)
cc_test(
name = "append_and_overwrite_test",
srcs = ["internal/append_and_overwrite_test.cc"],
copts = ABSL_TEST_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
":append_and_overwrite",
"//absl/log:absl_check",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
)
cc_test(
name = "match_test",
size = "small",
@@ -625,6 +652,7 @@ cc_library(
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
":append_and_overwrite",
":cord_internal",
":cordz_info",
":cordz_update_scope",