| 5241 | namespace |
| 5242 | { |
| 5243 | class xpath_string |
| 5244 | { |
| 5245 | const char_t* _buffer; |
| 5246 | bool _uses_heap; |
| 5247 | |
| 5248 | static char_t* duplicate_string(const char_t* string, size_t length, xpath_allocator* alloc) |
| 5249 | { |
| 5250 | char_t* result = static_cast<char_t*>(alloc->allocate((length + 1) * sizeof(char_t))); |
| 5251 | assert(result); |
| 5252 | |
| 5253 | memcpy(result, string, length * sizeof(char_t)); |
| 5254 | result[length] = 0; |
| 5255 | |
| 5256 | return result; |
| 5257 | } |
| 5258 | |
| 5259 | static char_t* duplicate_string(const char_t* string, xpath_allocator* alloc) |
| 5260 | { |
| 5261 | return duplicate_string(string, strlength(string), alloc); |
| 5262 | } |
| 5263 | |
| 5264 | public: |
| 5265 | xpath_string(): _buffer(PUGIXML_TEXT("")), _uses_heap(false) |
| 5266 | { |
| 5267 | } |
| 5268 | |
| 5269 | explicit xpath_string(const char_t* str, xpath_allocator* alloc) |
| 5270 | { |
| 5271 | bool empty = (*str == 0); |
| 5272 | |
| 5273 | _buffer = empty ? PUGIXML_TEXT("") : duplicate_string(str, alloc); |
| 5274 | _uses_heap = !empty; |
| 5275 | } |
| 5276 | |
| 5277 | explicit xpath_string(const char_t* str, bool use_heap): _buffer(str), _uses_heap(use_heap) |
| 5278 | { |
| 5279 | } |
| 5280 | |
| 5281 | xpath_string(const char_t* begin, const char_t* end, xpath_allocator* alloc) |
| 5282 | { |
| 5283 | assert(begin <= end); |
| 5284 | |
| 5285 | bool empty = (begin == end); |
| 5286 | |
| 5287 | _buffer = empty ? PUGIXML_TEXT("") : duplicate_string(begin, static_cast<size_t>(end - begin), alloc); |
| 5288 | _uses_heap = !empty; |
| 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 | } |
no outgoing calls
no test coverage detected