0
0
mirror of https://github.com/zeux/pugixml.git synced 2024-12-29 07:19:43 +08:00

883 Commits

Author SHA1 Message Date
Arseny Kapoulkine
f68a320a02 tests: Improve test coverage 2014-11-01 11:45:13 +01:00
Arseny Kapoulkine
25926c6206 XPath: Fix undefined behavior while calling memcpy
Calling memcpy(x, 0, 0) is technically undefined (although it should usually
be a no-op).

Fixes #20.
2014-11-01 10:48:14 +01:00
Arseny Kapoulkine
97893ad738 Fix first-time make config=coverage test
Not sure why xargs -r is not the default...
2014-11-01 08:59:49 +01:00
Arseny Kapoulkine
21cff3bca2 Fix several cppcheck warnings. 2014-10-28 17:10:41 -07:00
Arseny Kapoulkine
6229138d80 Optimize node printing by using raw pointers
This lets us do fewer null pointer checks (making printing 2% faster with -O3)
and removes a lot of function calls (making printing 20% faster with -O0).
2014-10-27 22:29:14 -07:00
Arseny Kapoulkine
c64d4820b1 XPath: Optimize [position()=expr] and [last()]
To get more benefits from constant predicate/filter optimization we rewrite
[position()=expr] predicates into [expr] for numeric expressions. Right now
the rewrite is only for entire expressions - it may be beneficial to split
complex expressions like [position()=constant and expr] into [constant][expr]
but that is more complicated.

last() does not depend on the node set contents so is "constant" as far as
our optimization is concerned so we can evaluate it once.
2014-10-27 18:50:09 -07:00
Arseny Kapoulkine
dbfe85a717 XPath: Only recognize numeric constant expressions
Numeric and boolean constant expressions in filters are different in that
to evaluate numeric expressions we need a sorted order, but to evaluate
boolean expressions we don't. The previously implemented optimization adds
an extra sorting step for constant boolean filters that will be more expensive
than redundant computations.

Since constant booleans are sort of an edge case, don't do this optimization.
This allows us to simplify apply_predicate_const to only handle numbers.
2014-10-26 10:27:50 -07:00
Arseny Kapoulkine
11ce004e04 XPath: Unify ast_filter/ast_predicate structure
Now expression is always _right for filter/predicate nodes to make optimize()
simpler. Additionally we now use predicate metadata to make is_posinv_step()
faster.

This introduces a weak ordering dependency in rewrite rules to optimize() -
classification has to be performed before other optimizations.
2014-10-26 10:11:22 -07:00
Arseny Kapoulkine
d5e29292c6 XPath: Optimize constant filters/predicates
If a filter/predicate expression is a constant, we don't need to evaluate it
for every nodeset element - we can evaluate it once and pick the right element
or keep/discard the entire collection.

If the expression is 1, we can early out on first node when evaluating the
node set - queries like following::item[1] are now significantly faster.

Additionally this change refactors filters/predicates to have additional
metadata describing the expression type in _test field that is filled during
optimization.

Note that predicate_constant selection right now is very simple (but captures
most common use cases except for maybe [last()]).
2014-10-26 09:37:18 -07:00
Arseny Kapoulkine
f31c14e1fd tests: Remove git2svn helper script! 2014-10-26 02:22:27 -07:00
Arseny Kapoulkine
3fc86dcdc6 Update README.md with new documentation URLs. 2014-10-26 02:21:29 -07:00
Arseny Kapoulkine
0e59ea8234 tests: Add a way for tests to verify allocation failure
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1081 99668b35-9821-0410-8761-19e4c4f06640
2014-10-26 03:46:28 +00:00
Arseny Kapoulkine
0b7964917c Fix node copying for some out of memory cases
A page can fail to allocate during attribute creation; this case was not
previously handled.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1080 99668b35-9821-0410-8761-19e4c4f06640
2014-10-25 16:37:16 +00:00
Arseny Kapoulkine
503abf607a Add 'coverage' configuration to Makefile.
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1079 99668b35-9821-0410-8761-19e4c4f06640
2014-10-25 05:28:37 +00:00
Arseny Kapoulkine
4363e8a651 Remove redundant null pointer checks.
When removing a node or attribute, we know that the parent has at least one
node/attribute so a null pointer check is redundant.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1078 99668b35-9821-0410-8761-19e4c4f06640
2014-10-25 03:17:55 +00:00
Arseny Kapoulkine
7b74531c1b tests: Fix test failure in PUGIXML_WCHAR_MODE
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1077 99668b35-9821-0410-8761-19e4c4f06640
2014-10-24 01:37:27 +00:00
Arseny Kapoulkine
546997683a tests: Add even more coverage tests
Also fix MSVC6 compilation (make convertions to function pointers explicit).

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1076 99668b35-9821-0410-8761-19e4c4f06640
2014-10-24 01:17:57 +00:00
Arseny Kapoulkine
903db8682a tests: Add more tests for better coverage
More tests for out-of-memory and other edge conditions

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1075 99668b35-9821-0410-8761-19e4c4f06640
2014-10-23 07:41:07 +00:00
Arseny Kapoulkine
bbd75fda46 tests: Improve test coverage
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1074 99668b35-9821-0410-8761-19e4c4f06640
2014-10-23 05:46:44 +00:00
Arseny Kapoulkine
4a7762af9d XPath: Optimize predicate evaluation
If the requested evaluation mode is not _all, we can use this mode for the
last predicate/filter expression and exit early.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1073 99668b35-9821-0410-8761-19e4c4f06640
2014-10-22 03:33:37 +00:00
Arseny Kapoulkine
28d24e5b6c XPath: Use node pointers in step_push/step_fill
Using pointers instead of node/attribute objects allows us to use knowledge
about the tree to guarantee that pointers are not null. This results in
less null checks (10-20% speedup with optimizations enabled) and less
function calls (5x speedup with optimizations disabled).

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1072 99668b35-9821-0410-8761-19e4c4f06640
2014-10-22 03:31:09 +00:00
Arseny Kapoulkine
3c92704c19 tests: Fix PUGIXML_WCHAR_MODE compilation
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1071 99668b35-9821-0410-8761-19e4c4f06640
2014-10-21 03:38:30 +00:00
Arseny Kapoulkine
7258aea09b tests: Assert on out-of-memory in tests
This should never happen but can improve debugging experience for
work-in-progress changes since that avoids memcpy() into negative memory
space (debugger can't backtrace from failed memcpy since it does not set
up the stack frame).

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1070 99668b35-9821-0410-8761-19e4c4f06640
2014-10-21 03:33:47 +00:00
Arseny Kapoulkine
7774cdd96e XPath: Make sure step_push is called with valid nodes
Some steps relied on step_push rejecting null inputs; this is no longer
the case. Additionally stepping now more rigorously filters null inputs.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1069 99668b35-9821-0410-8761-19e4c4f06640
2014-10-21 03:33:37 +00:00
Arseny Kapoulkine
45b6315d99 tests: Add a coverage test for unspecified_bool
It's unfortunate that we can even do that...

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1068 99668b35-9821-0410-8761-19e4c4f06640
2014-10-20 01:00:56 +00:00
Arseny Kapoulkine
1b8b87904b XPath: Introduce _first/_any set evaluation modes
Sometimes when evaluating the node set we don't need the entire set and
only need the first element in docorder or any element. In the absence of
iterator support we can still use this information to short-circuit
traversals.

This does not have any effect on straightforward node collection queries,
but frequently improves performance of complex queries with predicates
etc. XMark benchmark gets 15x faster with some queries enjoying 100x
speedup on 10 Mb dataset due to a significant complexity improvement.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1067 99668b35-9821-0410-8761-19e4c4f06640
2014-10-20 01:00:48 +00:00
Arseny Kapoulkine
2d4e549049 docs: Update XPath documentation
Add documentation for xpath_query::evaluate_node and change
select_single_node to select_node in documentation and samples.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1066 99668b35-9821-0410-8761-19e4c4f06640
2014-10-19 07:34:02 +00:00
Arseny Kapoulkine
c3eb9c92a8 XPath: Rename xml_node::select_single_node to ::select_node
select_node is shorter and mistyping nodes as node or vice versa should
not lead to any issues since return types are substantially different.

select_single_node method still works and will be deprecated with an
attribute and removed at some point.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1065 99668b35-9821-0410-8761-19e4c4f06640
2014-10-19 07:33:51 +00:00
Arseny Kapoulkine
f663558875 XPath: Introduce xpath_query::evaluate_node
This method is equivalent to xml_node::select_single_node. This makes
select_single_node faster in certain cases by avoiding an allocation and -
more importantly - paves the way for future step optimizations.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1064 99668b35-9821-0410-8761-19e4c4f06640
2014-10-19 07:33:42 +00:00
Arseny Kapoulkine
72ec01c5f6 XPath: Extend the descendant-or-self optimization
Use descendant-or-self::node() transformation for self, descendant and
descendant-or-self axis. Self axis should be semi-frequent; descendant
axes should not really be used with // but if they ever are the complexity
of the step becomes quadratic so it's better to optimize this if possible.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1063 99668b35-9821-0410-8761-19e4c4f06640
2014-10-18 15:28:02 +00:00
Arseny Kapoulkine
45e0c726f0 tests: Disable tests that rely on ceil() on CLR
CLR x64 JIT does not implement ceil() properly (ceil(-0.1) returns
positive zero instead of negative zero). Disable the relevant portions of
tests so that everything else is green...

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1062 99668b35-9821-0410-8761-19e4c4f06640
2014-10-16 06:41:04 +00:00
Arseny Kapoulkine
5da51dff27 XPath: Optimize attribute axis lookup
When looking for an attribute by name, finding the first attribute means
we can stop looking since attribute names are unique. This makes some
queries faster by 40%.

Another very common pattern in XPath queries is finding an attribute with
a specified value using a predicate (@name = 'value'). While we perform an
optimal amount of traversal in that case, there is a substantial overhead
with evaluating the nodes, saving and restoring the stack state, pushing
the attribute node into a set, etc. Detecting this pattern allows us to
use optimized code, resulting in up to 2x speedup for some queries.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1061 99668b35-9821-0410-8761-19e4c4f06640
2014-10-16 03:46:42 +00:00
Arseny Kapoulkine
883031fb45 XPath: Fix optimization bug with //name[last()]
The actual condition for the optimization is invariance from context list
-- this includes both position() and last().

Instead of splitting the posinv concept just include last() into
non-posinv expressions - this requires sorting for boolean predicates that
depend on last() and do not depend on position(). These cases should be
very rare.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1060 99668b35-9821-0410-8761-19e4c4f06640
2014-10-15 06:05:49 +00:00
Arseny Kapoulkine
87d4f03187 tests: Add a test for printing comments that contain --
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1059 99668b35-9821-0410-8761-19e4c4f06640
2014-10-14 04:11:26 +00:00
Arseny Kapoulkine
e7d2540c1a Adjust comment output to avoid malformed documents.
Comment value can not contain the string "--" or end with "-". Since
comments do not support escaping, we're handling this by adding an extra
space after the first "-". A string of "-" thus turns into "- - - ...".

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1058 99668b35-9821-0410-8761-19e4c4f06640
2014-10-14 04:11:17 +00:00
Arseny Kapoulkine
ccf8adce05 Swap insert_attribute_* implementations
Make sure their order is consistent with the order of declaration in
header file.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1057 99668b35-9821-0410-8761-19e4c4f06640
2014-10-11 02:34:42 +00:00
Arseny Kapoulkine
f4f55051d6 Refactor node/attribute tree operations
All ad-hoc attribute operations are now implemented as explicit low-level
functions, and xml_node just uses them. Additionally extract commonly used
is_attribute_of and move detaching of node from append_node to remove_node
- append_node now only works on detached nodes (small increase in parsing
  performance).

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1056 99668b35-9821-0410-8761-19e4c4f06640
2014-10-11 02:16:41 +00:00
Arseny Kapoulkine
d69127d78e Fix Borland C++ compilation errors/warnings
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1055 99668b35-9821-0410-8761-19e4c4f06640
2014-10-10 02:22:49 +00:00
Arseny Kapoulkine
9e6dcc292d tests: Add XPath sorting test
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1054 99668b35-9821-0410-8761-19e4c4f06640
2014-10-05 08:39:44 +00:00
Arseny Kapoulkine
89f2f00da4 XPath: Store string length inside string object
When xpath_string is heap-allocated we always know the length of the
string at some point - it is now stored in the object. This reduces
redundant string length calculations and makes string_value() much faster
in case it has to concatenate strings.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1053 99668b35-9821-0410-8761-19e4c4f06640
2014-10-05 07:58:05 +00:00
Arseny Kapoulkine
5239fcbd00 XPath: Implement optimized translate()
translate() with constant arguments now uses a 128-byte table and a table
lookup instead of searching characters in the source string. The table is
generated during query optimization.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1052 99668b35-9821-0410-8761-19e4c4f06640
2014-10-05 07:57:58 +00:00
Arseny Kapoulkine
b17501c3fb tests: Add XPath sorting tests and a simple test for numeric predicates
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1051 99668b35-9821-0410-8761-19e4c4f06640
2014-10-05 04:20:52 +00:00
Arseny Kapoulkine
a3b23751ae Optimize XPath document order comparator
Node ancestor search now terminates early if ancestor is found before the
document root (only happens if nodes were at the same depth).

Sibling search now steps synchronously for left and right nodes to avoid
worst-case performance when we go in the wrong direction and have to scan
a big list (this comes at the cost of average performance since in the
best case we do 2x more operations).

Node comparison is now done using node pointers to elide some null
comparisons since the structure of the search guarantees that they are
handled properly.

All of the above results in ~2x faster document order comparison on
complex documents.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1050 99668b35-9821-0410-8761-19e4c4f06640
2014-10-05 04:20:47 +00:00
Arseny Kapoulkine
e66356715c Optimize XPath sorting for sorted sequences
XPath evaluation frequently produces sequences that are sorted but are not
tagged as such (area for improvement...). Doing a linear scan before
sorting is cheap and results in tremendous speedup for already sorted
sequences (especially if document_buffer_order optimization does not
apply).

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1049 99668b35-9821-0410-8761-19e4c4f06640
2014-10-05 04:20:38 +00:00
Arseny Kapoulkine
42219590f3 Optimize unrolled scanning for MSVC
While gcc and clang can eliminate dependency on s in the inner loop of
PUGI__SCANWHILE_UNROLL, MSVC emits a series of register increments.
Rewriting the code to explicitly remove the dependency keeps similar
codegen on gcc/clang but improves codegen on MSVC for a 10% performance
boost.

Also use unrolled scanning in text_output_escaped (2% faster).

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1048 99668b35-9821-0410-8761-19e4c4f06640
2014-10-04 05:03:33 +00:00
Arseny Kapoulkine
8a402b480f Fix whitespace indentation
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1047 99668b35-9821-0410-8761-19e4c4f06640
2014-10-03 05:23:07 +00:00
Arseny Kapoulkine
c4ecc406d2 Reorganize xml_memory_page structure
The page no longer contains 'data' field to use sizeof everywhere instead
of offsetof/sizeof inconsistency (that is required because some compilers
don't recognize offsetof as compile-time constant).

The page no longer contains 'memory' field that is now encoded as an
offset byte before the page - this allows us to save one pointer from the
static page in the document to keep the size the same as in v1.2 (binary
compatibility).

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1046 99668b35-9821-0410-8761-19e4c4f06640
2014-10-03 05:18:03 +00:00
Arseny Kapoulkine
daa48183f9 Remove document buffer order flag from document node
Use the same flag that is used for marking name/value in nodes/attributes
as shared. This reduces document structure size and makes some amount of
sense (although admittedly is a bit of a hack).

We need to bring document _memory size back down to 192 bytes and this is
the first step.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1045 99668b35-9821-0410-8761-19e4c4f06640
2014-10-03 05:17:56 +00:00
Arseny Kapoulkine
f3b220ca4e tests: Fix MSVC6 compilation
Also fixes PUGIXML_NO_STL compilation and makes it possible to build with
any version of new Windows SDK.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1044 99668b35-9821-0410-8761-19e4c4f06640
2014-10-03 02:40:11 +00:00
Arseny Kapoulkine
04913dc358 Optimize node_copy_tree by switching to pointers
xml_node objects carry an overhead since they perform NULL checks - in
case of copying a hierarchy we know that we only traverse valid nodes so
we don't need to do this. This makes copyless copy 16% faster.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1043 99668b35-9821-0410-8761-19e4c4f06640
2014-10-03 02:37:29 +00:00