|
32 | 32 | #include "absl/base/nullability.h" |
33 | 33 | #include "absl/strings/ascii.h" |
34 | 34 | #include "absl/strings/charset.h" |
| 35 | +#include "absl/strings/internal/append_and_overwrite.h" |
35 | 36 | #include "absl/strings/internal/escaping.h" |
36 | | -#include "absl/strings/internal/resize_uninitialized.h" |
37 | 37 | #include "absl/strings/internal/utf8.h" |
38 | 38 | #include "absl/strings/numbers.h" |
39 | 39 | #include "absl/strings/resize_and_overwrite.h" |
@@ -446,22 +446,22 @@ void CEscapeAndAppendInternal(absl::string_view src, |
446 | 446 |
|
447 | 447 | // We keep 3 slop bytes so that we can call `little_endian::Store32` |
448 | 448 | // invariably regardless of the length of the escaped character. |
449 | | - constexpr size_t slop_bytes = 3; |
| 449 | + constexpr size_t kSlopBytes = 3; |
450 | 450 | size_t cur_dest_len = dest->size(); |
451 | | - size_t new_dest_len = cur_dest_len + escaped_len + slop_bytes; |
452 | | - ABSL_INTERNAL_CHECK(new_dest_len > cur_dest_len, "std::string size overflow"); |
453 | | - strings_internal::AppendUninitializedTraits<std::string>::Append( |
454 | | - dest, escaped_len + slop_bytes); |
455 | | - char* append_ptr = &(*dest)[cur_dest_len]; |
456 | | - |
457 | | - for (char c : src) { |
458 | | - unsigned char uc = static_cast<unsigned char>(c); |
459 | | - size_t char_len = kCEscapedLen[uc]; |
460 | | - uint32_t little_endian_uint32 = kCEscapedLittleEndianUint32Array[uc]; |
461 | | - little_endian::Store32(append_ptr, little_endian_uint32); |
462 | | - append_ptr += char_len; |
463 | | - } |
464 | | - dest->resize(new_dest_len - slop_bytes); |
| 451 | + size_t append_buf_len = cur_dest_len + escaped_len + kSlopBytes; |
| 452 | + ABSL_INTERNAL_CHECK(append_buf_len > cur_dest_len, |
| 453 | + "std::string size overflow"); |
| 454 | + strings_internal::StringAppendAndOverwrite( |
| 455 | + *dest, append_buf_len, [src, escaped_len](char* append_ptr, size_t) { |
| 456 | + for (char c : src) { |
| 457 | + unsigned char uc = static_cast<unsigned char>(c); |
| 458 | + size_t char_len = kCEscapedLen[uc]; |
| 459 | + uint32_t little_endian_uint32 = kCEscapedLittleEndianUint32Array[uc]; |
| 460 | + little_endian::Store32(append_ptr, little_endian_uint32); |
| 461 | + append_ptr += char_len; |
| 462 | + } |
| 463 | + return escaped_len; |
| 464 | + }); |
465 | 465 | } |
466 | 466 |
|
467 | 467 | // Reverses the mapping in Base64EscapeInternal; see that method's |
|
0 commit comments