| 5289 | } |
| 5290 | |
| 5291 | void append(const xpath_string& o, xpath_allocator* alloc) |
| 5292 | { |
| 5293 | // skip empty sources |
| 5294 | if (!*o._buffer) return; |
| 5295 | |
| 5296 | // fast append for constant empty target and constant source |
| 5297 | if (!*_buffer && !_uses_heap && !o._uses_heap) |
| 5298 | { |
| 5299 | _buffer = o._buffer; |
| 5300 | } |
| 5301 | else |
| 5302 | { |
| 5303 | // need to make heap copy |
| 5304 | size_t target_length = strlength(_buffer); |
| 5305 | size_t source_length = strlength(o._buffer); |
| 5306 | size_t length = target_length + source_length; |
| 5307 | |
| 5308 | // allocate new buffer |
| 5309 | char_t* result = static_cast<char_t*>(alloc->reallocate(_uses_heap ? const_cast<char_t*>(_buffer) : 0, (target_length + 1) * sizeof(char_t), (length + 1) * sizeof(char_t))); |
| 5310 | assert(result); |
| 5311 | |
| 5312 | // append first string to the new buffer in case there was no reallocation |
| 5313 | if (!_uses_heap) memcpy(result, _buffer, target_length * sizeof(char_t)); |
| 5314 | |
| 5315 | // append second string to the new buffer |
| 5316 | memcpy(result + target_length, o._buffer, source_length * sizeof(char_t)); |
| 5317 | result[length] = 0; |
| 5318 | |
| 5319 | // finalize |
| 5320 | _buffer = result; |
| 5321 | _uses_heap = true; |
| 5322 | } |
| 5323 | } |
| 5324 | |
| 5325 | const char_t* c_str() const |
| 5326 | { |
no test coverage detected