Add missing commit from shallow_copy branch

This commit is contained in:
halx99 2021-12-23 21:14:51 +08:00
parent f0259eb00a
commit d3a8b86f17
2 changed files with 12 additions and 4 deletions

View File

@ -432,12 +432,14 @@ PUGI__NS_BEGIN
#endif #endif
// extra metadata bits // extra metadata bits
static const uintptr_t xml_memory_page_contents_const_mask = 128;
static const uintptr_t xml_memory_page_contents_shared_mask = 64; static const uintptr_t xml_memory_page_contents_shared_mask = 64;
static const uintptr_t xml_memory_page_name_allocated_mask = 32; static const uintptr_t xml_memory_page_name_allocated_mask = 32;
static const uintptr_t xml_memory_page_value_allocated_mask = 16; static const uintptr_t xml_memory_page_value_allocated_mask = 16;
static const uintptr_t xml_memory_page_type_mask = 15; static const uintptr_t xml_memory_page_type_mask = 15;
// combined masks for string uniqueness // combined masks for string uniqueness
static const uintptr_t xml_memory_page_contents_const_or_shared_mask = xml_memory_page_contents_const_mask | xml_memory_page_contents_shared_mask;
static const uintptr_t xml_memory_page_name_allocated_or_shared_mask = xml_memory_page_name_allocated_mask | xml_memory_page_contents_shared_mask; static const uintptr_t xml_memory_page_name_allocated_or_shared_mask = xml_memory_page_name_allocated_mask | xml_memory_page_contents_shared_mask;
static const uintptr_t xml_memory_page_value_allocated_or_shared_mask = xml_memory_page_value_allocated_mask | xml_memory_page_contents_shared_mask; static const uintptr_t xml_memory_page_value_allocated_or_shared_mask = xml_memory_page_value_allocated_mask | xml_memory_page_contents_shared_mask;
@ -2381,7 +2383,7 @@ PUGI__NS_BEGIN
inline bool strcpy_insitu_allow(size_t length, const Header& header, uintptr_t header_mask, char_t* target) inline bool strcpy_insitu_allow(size_t length, const Header& header, uintptr_t header_mask, char_t* target)
{ {
// never reuse shared memory // never reuse shared memory
if (header & xml_memory_page_contents_shared_mask) return false; if (header & xml_memory_page_contents_const_or_shared_mask) return false;
size_t target_length = strlength(target); size_t target_length = strlength(target);
@ -2410,6 +2412,9 @@ PUGI__NS_BEGIN
dest = source_length == 0 ? NULL : const_cast<String>(source); dest = source_length == 0 ? NULL : const_cast<String>(source);
header &= ~header_mask; header &= ~header_mask;
// mark dest as shared to avoid reuse document buffer memory
header |= xml_memory_page_contents_const_mask;
return true; return true;
} }
else if (dest && strcpy_insitu_allow(source_length, header, header_mask, dest)) else if (dest && strcpy_insitu_allow(source_length, header, header_mask, dest))
@ -2441,6 +2446,9 @@ PUGI__NS_BEGIN
dest = buf; dest = buf;
header |= header_mask; header |= header_mask;
// remove dest shared mask for continue reuse document buffer memory
header &= ~xml_memory_page_contents_const_mask;
return true; return true;
} }
} }
@ -4768,7 +4776,7 @@ PUGI__NS_BEGIN
template <typename String, typename Header> template <typename String, typename Header>
PUGI__FN bool set_value_bool(String& dest, int& dest_len, Header& header, uintptr_t header_mask, bool value) PUGI__FN bool set_value_bool(String& dest, int& dest_len, Header& header, uintptr_t header_mask, bool value)
{ {
return strcpy_insitu(dest, dest_len, header, header_mask, value ? PUGIXML_TEXT("true") : PUGIXML_TEXT("false"), value ? 4 : 5); return strcpy_insitu(dest, dest_len, header, header_mask, value ? PUGIXML_TEXT("true") : PUGIXML_TEXT("false"), value ? 4 : 5, true);
} }
PUGI__FN xml_parse_result load_buffer_impl(xml_document_struct* doc, xml_node_struct* root, void* contents, size_t size, unsigned int options, xml_encoding encoding, bool is_mutable, bool own, char_t** out_buffer) PUGI__FN xml_parse_result load_buffer_impl(xml_document_struct* doc, xml_node_struct* root, void* contents, size_t size, unsigned int options, xml_encoding encoding, bool is_mutable, bool own, char_t** out_buffer)

View File

@ -255,8 +255,8 @@ namespace pugi {
bool value; bool value;
operator bool() const { return value; } operator bool() const { return value; }
}; };
static const boolean true_value(true); static const boolean (true_value)(true);
static const boolean false_value(false); static const boolean (false_value)(false);
} // namespace pugi } // namespace pugi
namespace pugi namespace pugi