0
0
mirror of https://github.com/zeux/pugixml.git synced 2024-12-31 00:13:01 +08:00

1259 Commits

Author SHA1 Message Date
Arseny Kapoulkine
97afc16ef2 tests: Add newline at the end of file 2015-05-22 20:20:03 -07:00
Arseny Kapoulkine
2a1aa9663b Fix MSVC7 compilation
Work around a name lookup bug by pulling auto_deleter name in the local
scope. We could also move auto_deleter to pugi:: namespace, but that
pollutes it unnecessarily for other compilers.
2015-05-22 18:05:30 -07:00
Arseny Kapoulkine
fc1dcab79d tests: Fix MSVC6 compilation 2015-05-22 08:43:36 -07:00
Arseny Kapoulkine
677e95010e Move default value handling into as_ functions
This makes get_value_* simpler and also works around DMC compilation issue.
2015-05-22 08:42:32 -07:00
Arseny Kapoulkine
243839012a XPath: Use strtod instead of atof
This makes code more consistent between wchar/utf8 mode.
2015-05-20 08:31:00 -07:00
Arseny Kapoulkine
e2358e5e3b tests: Split fp roundtrip test into float and double 2015-05-20 08:05:43 -07:00
Arseny Kapoulkine
f828eae3ea Implement xml_node::attribute with a hint
Extra argument 'hint' is used to start the attribute lookup; if the attribute
is not found the lookup is restarted from the beginning of the attriubte list.

This allows to optimize attribute lookups if you need to get many attributes
from the node and can make assumptions about the likely ordering. The code is
correct regardless of the order, but it is faster than using vanilla lookups
if the order matches the calling order.

Fixes #30.
2015-05-14 08:04:06 -07:00
Arseny Kapoulkine
01f627a4d7 tests: Fix address sanitizer detection for GCC 2015-05-12 21:49:44 -07:00
Arseny Kapoulkine
107239c927 Add config=sanitize support to Makefile 2015-05-12 20:57:57 -07:00
Arseny Kapoulkine
59ce480f96 Add Visual Studio 2015 to AppVeyor 2015-05-12 20:55:59 -07:00
Arseny Kapoulkine
7342c5ed8c tests: Disable page allocator if address sanitizer is active
Address sanitizer can detect underflows so we don't really need the custom
allocator.

Additionally, custom allocator can return memory that is not pointer-aligned;
this causes undefined behavior sanitizer to complain.
2015-05-12 20:16:51 -07:00
Arseny Kapoulkine
9f7994ed71 tests: Fix clang 3.7 warning
Work around -Wself-move using ref-deref.
2015-05-12 20:02:53 -07:00
Arseny Kapoulkine
708952d84e Update README.md 2015-05-03 19:15:47 -07:00
Arseny Kapoulkine
51faffa238 Update README.md 2015-05-03 19:12:23 -07:00
Arseny Kapoulkine
272c80f67c Switch Travis CI to use Docker 2015-05-03 18:40:21 -07:00
Arseny Kapoulkine
86548e14bd Fix NO_STL+NO_XPATH mode
auto_deleter is now used in all modes so we can't exclude it from compilation.
2015-05-03 17:58:20 -07:00
Arseny Kapoulkine
cff35dfa31 tests: Fix MSVC6 compatibility
Apply the usual workaround for for scoping issues. Also fix integer conversion
warning for BorlandC.
2015-05-03 17:58:20 -07:00
Arseny Kapoulkine
873c8e5011 Merge pull request #42 from zeux/compact
Implement compact mode.

This introduces a new storage mode that dramatically reduces node size at some performance cost.
The mode is enabled by defining PUGIXML_COMPACT. This does not change API/ABI - all existing functionality still works.

The pointers are stored using delta encoding and bytes, with some additional tricks to make encoding more optimal for e.g. parent pointer and string pointers. Since the node is fixed size, we have to fall back to a hash table if the pointer does not fit. Thus all DOM operations still have amortized complexity - constant number of operations if you don't need the hash table and amortized constant if you do.

Aside from some performance loss (which is inevitable since decoding takes time), the only other caveat is that we can't remove entries from the hash table - so in some edge cases with a lot of node removals the peak memory consumption can grow indefinitely. In theory we can implement this later; it's unclear that this is useful at this point.

The resulting node/attribute sizes are as follows:
non-compact node: 28b 32-bit, 56b 64-bit
compact node: 12b 32/64-bit
non-compact attribute: 20b 32-bit, 40b 64-bit
compact attribute: 8b 32/64-bit
2015-05-03 11:42:19 -07:00
Arseny Kapoulkine
9597265a12 Cleanup before merge 2015-05-03 11:02:42 -07:00
Arseny Kapoulkine
b1965061af Fix MSVC warning 2015-05-03 09:21:23 -07:00
Arseny Kapoulkine
f67e761970 Fix MSVC build 2015-05-02 16:41:21 -07:00
Arseny Kapoulkine
20e2041f14 Reorder conditions in compact_string implementation
Now compact_string matches compact_pointer_parent.

Turns out PUGI__UNLIKELY is good at reordering conditions but usually does not
really affect performance. Since MSVC should treat "if" branches as taken and
does not support branch probabilities, don't use them if we don't need to.
2015-05-02 15:57:46 -07:00
Arseny Kapoulkine
f8915c8eab Minor refactoring 2015-05-02 15:47:59 -07:00
Arseny Kapoulkine
fa8663c066 Revise marker deletion strategy
Instead of checking if the object being removed allocated a marker, mark the
marker block as deleted immediately upon allocation. This simplifies the logic
and prevents extra markers from being inserted if we allocate/deallocate the
same node indefinitely.

Also change marker pointer type to uint32_t*.
2015-05-02 15:40:30 -07:00
Arseny Kapoulkine
613301ce51 Optimize compact_string
First assignment uses a fast path; second assignment uses a specialized
path as well.
2015-05-02 14:52:27 -07:00
Arseny Kapoulkine
19d43d39fc tests: Add one more page reclamation test 2015-05-02 09:45:26 -07:00
Arseny Kapoulkine
b1578e32a5 Fix node deallocation
When we deallocate nodes/attributes that allocated the marker we have to
adjust the size accordingly, and dismiss the marker in case it gets
overwritten with something else...
2015-05-02 09:38:14 -07:00
Arseny Kapoulkine
dec4267fb1 Implement efficient compact_header storage
Header is now just 2 bytes, with optional additonal 4 bytes that are only
allocated for every 85 nodes / 128 attributes.
2015-05-02 08:59:47 -07:00
Arseny Kapoulkine
e4c539a869 Implement compact_string with shared storage 2015-05-01 22:47:53 -07:00
Arseny Kapoulkine
3915f7b144 Rename compact_string to compact_string_fat 2015-05-01 21:09:26 -07:00
Arseny Kapoulkine
bc5eb22b71 Revert to name/value storage inside node
This temporarily increases the node size to 16 bytes - we'll bring it back.

It allows us to remove the horrible node_pi hack and to reduce the amount of
changes against master. This comes at the price of not decreasing basline
xml_node_struct size.

The compact xml_node_struct is also increased by this change but a followup
change will reduce *both* xml_attribute_struct and xml_node_struct (to 8/12
bytes).
2015-05-01 20:03:17 -07:00
Arseny Kapoulkine
dede617d9f tests: Fix spurious failures in compact mode
The memory_large_allocations test sometimes classified hash allocations
as page allocations since hash table could reach 512 entries.
2015-04-29 09:21:04 -07:00
Arseny Kapoulkine
b2399f5ab5 Refactor offset_debug
Split a long line into multiple statements.
2015-04-29 09:20:08 -07:00
Arseny Kapoulkine
44e4f17348 Change xml_node_struct field order to match compact
Also remove useless comments.
2015-04-22 09:53:04 -07:00
Arseny Kapoulkine
3643b505a6 Fix node_pi memory leak 2015-04-22 08:38:52 -07:00
Arseny Kapoulkine
4223b4a3f0 Make xml_node::value() structure consistent with set_* 2015-04-22 08:30:53 -07:00
Arseny Kapoulkine
e4e2259646 Remove compact_header::operator uintptr_t
We used this in two cases - to get the page pointer and to test flags.

We now use PUGI__GETPAGE for getting the page pointer and operator& to test
flags - this makes getting node type significantly faster since it does not
require page pointer reconstruction.
2015-04-22 08:26:47 -07:00
Arseny Kapoulkine
12744fd1fa Remove redundant has_value check 2015-04-22 07:52:20 -07:00
Arseny Kapoulkine
b87160013b Use has_name/has_value in set_name/set_value 2015-04-22 07:51:02 -07:00
Arseny Kapoulkine
4649914447 Optimize and refactor compact_pointer implementations
Clarify the offset applied when encoding the pointer difference.
Make decoding diff slightly more clear - no effect on performance.

Adjust branch weighting in compact_string encoding - 0.5% faster.
Use uint16_t in compact_pointer_parent - 2% faster.
2015-04-22 07:36:32 -07:00
Arseny Kapoulkine
33b2efe318 Optimize xml_allocator::reserve()
Make sure compact_hash_table::rehash() is not inlined - that way reserve() is
inlined so the fast path has no extra function calls.

Also use subtraction instead of multiplication when checking capacity.
2015-04-21 23:02:44 -07:00
Arseny Kapoulkine
52bcb4ecd6 tests: Adjust allocation thresholds to fix tests 2015-04-21 21:35:54 -07:00
Arseny Kapoulkine
f9983ea2ed Merge branch 'master' into compact 2015-04-21 21:27:44 -07:00
Arseny Kapoulkine
a6cc636a6b tests: Fix MSVC warnings 2015-04-21 21:07:58 -07:00
Arseny Kapoulkine
250d020e9b Use -std=c++0x instead of -std=c++11 2015-04-21 20:46:33 -07:00
Arseny Kapoulkine
8d4544f2e1 Enable C++11 in Makefile 2015-04-21 20:32:40 -07:00
Arseny Kapoulkine
4eadece45f tests: Add move semantics tests
Also test ranged for and copying big xpath_variable_set objects (to make
sure we actually handle hash collisions properly)
2015-04-21 19:44:19 -07:00
Arseny Kapoulkine
83b894b8f1 XPath: Implement move semantics support
xpath_query, xpath_node_set and xpath_variable_set are now moveable.

This is a nice performance optimization for variable/node sets, and enables
storing xpath_query in containers without using pointers (it's only possible
now since the query is not copyable).
2015-04-21 19:42:31 -07:00
Arseny Kapoulkine
a414c5c52d Fix compilation warning in some configurations 2015-04-21 10:02:26 -07:00
Arseny Kapoulkine
cbf3807ad4 Implement copy ctor/assignment for xpath_variable_set
xpath_variable_set is essentially an associative container; it's about time it
became copyable.

Implementation is slightly tricky due to out of memory handling. Both copy ctor
and assignment operator have strong exception guarantee (even if exceptions are
disabled! which translates to "roll back on allocation errors").
2015-04-15 23:22:31 -07:00