| 41 | } |
| 42 | |
| 43 | void DynamicBuffer::AddJoinedString(const std::vector<StringRef>& strings, |
| 44 | char separator) { |
| 45 | // Resize the data buffer. |
| 46 | int total_len = strings.size() - 1; |
| 47 | for (StringRef ref : strings) { |
| 48 | total_len += ref.len; |
| 49 | } |
| 50 | data_.resize(data_.size() + total_len); |
| 51 | |
| 52 | int current_idx = 0; |
| 53 | for (StringRef ref : strings) { |
| 54 | char* dst = data_.data() + offset_.back() + current_idx; |
| 55 | |
| 56 | // Fill separator if not first string. |
| 57 | if (current_idx != 0) { |
| 58 | *dst = separator; |
| 59 | ++dst; |
| 60 | ++current_idx; |
| 61 | } |
| 62 | |
| 63 | // Fill content of the string. |
| 64 | memcpy(dst, ref.str, ref.len); |
| 65 | current_idx += ref.len; |
| 66 | } |
| 67 | offset_.push_back(offset_.back() + total_len); |
| 68 | } |
| 69 | |
| 70 | int DynamicBuffer::WriteToBuffer(char** buffer) { |
| 71 | // Allocate sufficient memory to tensor buffer. |