| 5913 | } |
| 5914 | |
| 5915 | void append(const xpath_string& o, xpath_allocator* alloc) |
| 5916 | { |
| 5917 | // skip empty sources |
| 5918 | if (!*o._buffer) return; |
| 5919 | |
| 5920 | // fast append for constant empty target and constant source |
| 5921 | if (!*_buffer && !_uses_heap && !o._uses_heap) |
| 5922 | { |
| 5923 | _buffer = o._buffer; |
| 5924 | } |
| 5925 | else |
| 5926 | { |
| 5927 | // need to make heap copy |
| 5928 | size_t target_length = strlength(_buffer); |
| 5929 | size_t source_length = strlength(o._buffer); |
| 5930 | size_t result_length = target_length + source_length; |
| 5931 | |
| 5932 | // allocate new buffer |
| 5933 | 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))); |
| 5934 | assert(result); |
| 5935 | |
| 5936 | // append first string to the new buffer in case there was no reallocation |
| 5937 | if (!_uses_heap) memcpy(result, _buffer, target_length * sizeof(char_t)); |
| 5938 | |
| 5939 | // append second string to the new buffer |
| 5940 | memcpy(result + target_length, o._buffer, source_length * sizeof(char_t)); |
| 5941 | result[result_length] = 0; |
| 5942 | |
| 5943 | // finalize |
| 5944 | _buffer = result; |
| 5945 | _uses_heap = true; |
| 5946 | } |
| 5947 | } |
| 5948 | |
| 5949 | const char_t* c_str() const |
| 5950 | { |
no test coverage detected