Append the given data to the string, resizing capacity as necessary.
| 145 | |
| 146 | // Append the given data to the string, resizing capacity as necessary. |
| 147 | void append(const void *src_v, size_t count) { |
| 148 | const uint8_t *src = reinterpret_cast<const uint8_t *>(src_v); |
| 149 | EnsureRoomForAppend(count); |
| 150 | ASAN_UNPOISON_MEMORY_REGION(data_ + len_, count); |
| 151 | |
| 152 | // appending short values is common enough that this |
| 153 | // actually helps, according to benchmarks. In theory |
| 154 | // memcpy_inlined should already be just as good, but this |
| 155 | // was ~20% faster for reading a large prefix-coded string file |
| 156 | // where each string was only a few chars different |
| 157 | if (count <= 4) { |
| 158 | uint8_t *p = &data_[len_]; |
| 159 | for (int i = 0; i < count; i++) { |
| 160 | *p++ = *src++; |
| 161 | } |
| 162 | } else { |
| 163 | strings::memcpy_inlined(&data_[len_], src, count); |
| 164 | } |
| 165 | len_ += count; |
| 166 | } |
| 167 | |
| 168 | // Append the given string to this string. |
| 169 | void append(const std::string &str) { |