22 Commits
Author SHA1 Message Date
udf2457 8cb3ddf6e3 Refactor IsMatcher to use slices.ContainsFunc 2026-09-04 15:38:40 +01:00
jvoisin 535ec7c4f2 perf: short-circuit IsMatcher on the first match
IsMatcher handled multi-node selections by calling m.Filter(s.Nodes) and
checking whether the returned slice was non-empty, forcing the matcher to walk
the whole selection and materialize all matches even though the API only needs
an existence check.

This commit replaces this with a simple loop over s.Nodes that calls m.Match(n)
and returns true on the first match. This also makes the single-node special
case unnecessary.

Benchmark results on arm64 over 10 runs:

name            old time/op   new time/op   delta
Is-8             4.67µs        1.32µs       -71.7%
IsPositional-8   21.44µs       0.82µs       -96.2%

name            old B/op      new B/op      delta
Is-8             96           80           -16.7%
IsPositional-8   1144         184          -83.9%

name            old allocs    new allocs    delta
Is-8             5            4            -20.0%
IsPositional-8   11           7            -36.4%
2026-05-27 15:19:58 +02:00
jvoisin d94aeb90e8 perf: short-circuit IsFunction, IsSelection, and IsNodes
These methods were building a full filtered Selection (via
FilterFunction/FilterSelection/FilterNodes -> winnow -> grep) only to
check Length() > 0. This commit replaces with early-return loops that stop at
the first match, significantly speeding them up:

name             old ns/op   new ns/op   delta
IsFunction-8     1530        3.9         -99.7%
IsSelection-8    1890        19.9        -98.9%
IsNodes-8        2016        19.9        -99.0%

name             old B/op    new B/op    delta
IsFunction-8     784         0           -100.0%
IsSelection-8    72          0           -100.0%
IsNodes-8        72          0           -100.0%

name             old allocs  new allocs  delta
IsFunction-8     28          0           -100.0%
IsSelection-8    3           0           -100.0%
IsNodes-8        3           0           -100.0%
2026-05-23 22:57:17 +02:00
Noah Santschi-Cooney 3855699cc0 Removed unnecessary if
IsMatcher returns false if len(s.Nodes) !> 0, so Is was double checking if len(s.Nodes) > 0
2018-01-17 13:49:09 +00:00
Martin Angers 2ab590df05 use a failing matcher if selector fails to compile, adjust tests 2016-06-15 09:27:17 -04:00
HARUYAMA Seigo d9b2b5ed51 cascadia has moved.
code.google.com/p/cascadia
->
github.com/andybalholm/cascadia
2015-03-28 11:15:11 +09:00
Martin Angers 251095afb5 start adding matcher functions 2014-11-06 21:43:08 -05:00
Martin Angers cc9b6f8c6f Merge branch 'master' into manipulation 2014-11-06 20:46:11 -05:00
Martin Angers 040cf98281 change paths to golang.org/x/, fails to build because cascadia has to switch too 2014-11-05 20:30:33 -05:00
Andrew Stone 25807d1884 property: Add/Remove/Toggle Class functions 2014-10-29 11:11:01 -04:00
Martin Angers 28cf4a77e1 more linting 2014-04-11 12:04:03 -04:00
Martin Angers 2c6687f6d3 lint 2014-04-11 12:00:17 -04:00
Martin Angers 27b24066a6 make regexp var package-level, compiled once. fixes #11 2013-05-06 20:19:21 -04:00
Dobrosław Żybort 474b169363 Update exp/html import paths 2013-02-12 20:32:16 +01:00
Martin Angers 0f850e5c82 remove commented code 2012-10-18 21:18:56 -04:00
Martin Angers b358595af5 remove Is with context, start benchmarks for traversal.go 2012-09-12 09:29:06 -04:00
Martin Angers 2d885ccd3a add tests for End() rollbacks, doc 2012-09-05 09:35:53 -04:00
Martin Angers 6e1e76af6b refactor Document to make Root a Selection, with all API available 2012-09-02 14:45:50 -04:00
Martin Angers db549966da add Is...() and tests 2012-08-31 14:31:29 -04:00
Martin Angers b89ed30e10 fix doc a little, start Is() 2012-08-31 11:26:24 -04:00
Martin Angers 437a1dc2a1 work on filter.go, needs tests now 2012-08-30 22:47:12 -04:00
Martin Angers de74d0bf97 reorganize code in what seems like a sane structure 2012-08-30 17:35:41 -04:00