p_css 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b70a7f4978f6311a69ce05d16a2c1aa00c4aa5b2f4f68cb885d259c84ad76a63
4
- data.tar.gz: 58d2dd272ab27d073338261d33d5a3d7012ae9ff1e61c0f724a56a0d78bd078d
3
+ metadata.gz: 7c7c770667eefbfabcfd7543684970c971588c7d31ef7eaa8dfde8dfc71382ec
4
+ data.tar.gz: fe5c819bb338d0417fed4e15fbf85f9c8a158038a0fd9d17e78e308c2e1c949f
5
5
  SHA512:
6
- metadata.gz: fcdd53e4472aa6f840efefdb6f930d8c3c7b5dee0b6b72f4e50c96f531028b01ce66e537bffee68aa885401c507657f773a8785a797b61a561c266b54e0e83fa
7
- data.tar.gz: 867129f911254dbc806c92d895428cc54d08d20df2d68664d57a99e52026d17c51d4b726c9b5f4f0493fc10301dc42a2d79e2be53dc5da5298f4d9934a2fe492
6
+ metadata.gz: cf33855007bc4c7691d7a9c726eb51f85215492643ec54c2510438a4d10da5afefa176cc062c8eab5774b4a86a23049c5b7b5f64f121682581f34aceb826870d
7
+ data.tar.gz: c72b82737b2c24a7585022da646135f743dfc9a59dc918267482f57ae2e68cd79dcfd6da106a14b6962ac2fd325ab09032a40e59148191d4146b08cc057ef37f
data/lib/css/cascade.rb CHANGED
@@ -35,8 +35,15 @@ module CSS
35
35
  # `state:` opts into stateful-pseudo matching — see
36
36
  # `Selectors::Matcher#matches?` for the shape. Defaults to the
37
37
  # stateless behavior (`:hover`, `:focus`, etc. never match).
38
- def resolve(element, inline_style: nil, state: nil)
39
- cache = {}
38
+ #
39
+ # `cache:` lets callers share a per-element context cache across many
40
+ # resolves. The default `{}` is local to one call. Pass a persistent
41
+ # Hash when the DOM is stable across many resolves — Context (tag, id,
42
+ # classes) computation runs once per element instead of per resolve.
43
+ # The caller is responsible for clearing/replacing the cache on DOM
44
+ # mutation.
45
+ def resolve(element, inline_style: nil, state: nil, cache: nil)
46
+ cache ||= {}
40
47
  candidates = collect_candidate_indexes(element, cache)
41
48
  order = 0
42
49
  matches = []
@@ -43,7 +43,7 @@ module CSS
43
43
  # the duration of a single matcher invocation.
44
44
  Context = Data.define(:tag, :id, :classes)
45
45
 
46
- EMPTY_CLASS_SET = Set.new.freeze
46
+ EMPTY_CLASSES = [].freeze
47
47
 
48
48
  def matches?(element, selector, cache: nil, state: nil)
49
49
  sel = selector.is_a?(String) ? Parser.parse_selector_list(selector) : selector
@@ -148,11 +148,15 @@ module CSS
148
148
  )
149
149
  end
150
150
 
151
+ # Returns an Array of class names. We deliberately don't wrap in a Set:
152
+ # construction allocates two objects (Array + Set), and on the typical
153
+ # 1–5 classes per element, Array#include? is fast enough that the
154
+ # construction win dominates the lookup penalty.
151
155
  def build_class_set(element)
152
156
  v = attr(element, 'class')
153
- return EMPTY_CLASS_SET if v.nil? || v.empty?
157
+ return EMPTY_CLASSES if v.nil? || v.empty?
154
158
 
155
- v.to_s.split(/\s+/).to_set
159
+ v.to_s.split(' ')
156
160
  end
157
161
 
158
162
  # Attribute matching ----------------------------------------------
data/lib/css/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CSS
2
- VERSION = '0.1.8'
2
+ VERSION = '0.1.9'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: p_css
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keita Urashima