| 6811 | } |
| 6812 | |
| 6813 | void append(const xpath_string& o, xpath_allocator* alloc) |
| 6814 | { |
| 6815 | // skip empty sources |
| 6816 | if (!*o._buffer) return; |
| 6817 | |
| 6818 | // fast append for constant empty target and constant source |
| 6819 | if (!*_buffer && !_uses_heap && !o._uses_heap) |
| 6820 | { |
| 6821 | _buffer = o._buffer; |
| 6822 | } |
| 6823 | else |
| 6824 | { |
| 6825 | // need to make heap copy |
| 6826 | size_t target_length = length(); |
| 6827 | size_t source_length = o.length(); |
| 6828 | size_t result_length = target_length + source_length; |
| 6829 | |
| 6830 | // allocate new buffer |
| 6831 | char_t* result = static_cast<char_t*>(alloc->reallocate(_uses_heap ? const_cast<char_t*>(_buffer) : 0, (target_length + 1) * sizeof(char_t), (result_length + 1) * sizeof(char_t))); |
| 6832 | assert(result); |
| 6833 | |
| 6834 | // append first string to the new buffer in case there was no reallocation |
| 6835 | if (!_uses_heap) memcpy(result, _buffer, target_length * sizeof(char_t)); |
| 6836 | |
| 6837 | // append second string to the new buffer |
| 6838 | memcpy(result + target_length, o._buffer, source_length * sizeof(char_t)); |
| 6839 | result[result_length] = 0; |
| 6840 | |
| 6841 | // finalize |
| 6842 | _buffer = result; |
| 6843 | _uses_heap = true; |
| 6844 | _length_heap = result_length; |
| 6845 | } |
| 6846 | } |
| 6847 | |
| 6848 | const char_t* c_str() const |
| 6849 | { |
no test coverage detected