leptris 1.9.222.1-x86_64-linux → 1.9.222.2-x86_64-linux

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: dca333815547515d8eca3e154d3b78f22343c8e61772d1b238f35bb9f5a89593
4
- data.tar.gz: cb9570da32327971d7ec4ff45ba9fd9f9b1aac00d08ef57849579e22a312a752
3
+ metadata.gz: 1a2572ad1d071c50c78534599f7fd5085eb10440ee977adfcde86fdeb54124e5
4
+ data.tar.gz: 8de31d649e8716712d6b323d5424cb95963a8360fad615a401da1b607fa6d993
5
5
  SHA512:
6
- metadata.gz: b68930a9057d620c4ddeb5380d9e2740d0c712144f6d68f0b2e5718edf8131b1c5acb56ab1414aa09ef670439e2a92f0f730957bd1cb26d2456f65538acb23fd
7
- data.tar.gz: a67c1b617d6517986843ae3fb550b15c6141b6e4c4e553b994d08531a334e3258eae7d0529863674164c30ae9a74c77561b223300fe19b1b3e2c54f09e925bb6
6
+ metadata.gz: '0209e0b311b3811bea6948f8d36dfa0053b63efd117fe76b3eb471c3182dca8acead4de51a679a7273900ebd8ed3a0c81189abe3849c2896b9885ecba12c6aea'
7
+ data.tar.gz: 61ae26f2a6e027e7cb2eec1326a24b1f722e158ead86db7496f6e27f28cdb1e7083105906e418f358ba04a4c13e07b154b872c2ac7f1055cb7087e36c220cb25
@@ -2150,6 +2150,34 @@ static VALUE nf_plan_structs_typed_p(VALUE self)
2150
2150
  return Qtrue;
2151
2151
  }
2152
2152
 
2153
+ /* ---- Bulk attribute rows (leptris-ruby#278) ----------------------
2154
+ * One C crossing per element: walks the attribute chain and
2155
+ * returns a flat [name, value, address, ...] array. Names
2156
+ * interned (they repeat), values fresh UTF-8 strings, addresses
2157
+ * as Integers for Attr c_handle reconstruction. Identical data
2158
+ * to the per-attribute FFI chain (first/next/get_name/get_value,
2159
+ * 4 crossings each) — the win amplifies with attribute density
2160
+ * (40-attr elements: ~7x on the listing). */
2161
+ static VALUE nf_attribute_rows(VALUE self, VALUE document, VALUE addr)
2162
+ {
2163
+ (void)self;
2164
+ (void)document;
2165
+ void *node = (void *)(uintptr_t)NUM2ULL(addr);
2166
+ VALUE out = rb_ary_new();
2167
+ if (f_node_type(node) != WS_NODE_ELEMENT) return out;
2168
+
2169
+ for (void *a = f_attr_first(node); a; a = f_attr_next(a)) {
2170
+ const char *an = f_attr_name(a);
2171
+ const char *av = f_attr_value(node, a);
2172
+ rb_ary_push(out, an ? rb_enc_interned_str(an, strlen(an),
2173
+ rb_utf8_encoding())
2174
+ : Qnil);
2175
+ rb_ary_push(out, av ? rb_utf8_str_new_cstr(av) : Qnil);
2176
+ rb_ary_push(out, ULL2NUM((uintptr_t)a));
2177
+ }
2178
+ return out;
2179
+ }
2180
+
2153
2181
  static VALUE nf_plan_structs(VALUE self, VALUE document, VALUE addr,
2154
2182
  VALUE spec)
2155
2183
  {
@@ -2732,6 +2760,8 @@ LEPTRIS_INIT_EXPORT void Init_native(void)
2732
2760
  nf_attribute_pairs, 2);
2733
2761
  rb_define_module_function(m_native, "plan_structs",
2734
2762
  nf_plan_structs, 3);
2763
+ rb_define_module_function(m_native, "attribute_rows",
2764
+ nf_attribute_rows, 2);
2735
2765
  rb_define_module_function(m_native, "plan_structs_typed?",
2736
2766
  nf_plan_structs_typed_p, 0);
2737
2767
  rb_define_module_function(m_native, "doc_handle_attach",
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Leptris
4
- VERSION = "1.9.222.1"
4
+ VERSION = "1.9.222.2"
5
5
  end
@@ -311,7 +311,11 @@ class Leptris::XML::Element < Leptris::XML::Node
311
311
 
312
312
  def attribute_nodes
313
313
  return @attribute_nodes if memo_hit?(@attribute_nodes_version)
314
- result = each_attribute.to_a
314
+ result = if NATIVE_ATTR_ROWS && @c_address && @document
315
+ attribute_rows_native
316
+ else
317
+ each_attribute.to_a
318
+ end
315
319
  if @document
316
320
  @attribute_nodes = result
317
321
  @attribute_nodes_version = @document.version
@@ -319,6 +323,26 @@ class Leptris::XML::Element < Leptris::XML::Node
319
323
  result
320
324
  end
321
325
 
326
+ # One C crossing per element (leptris-ruby#278): the native face
327
+ # walks the attribute chain and returns flat [name, value,
328
+ # address] triples; the Attr value objects are minted from them
329
+ # with zero further engine crossings — identical objects to
330
+ # each_attribute. The win amplifies with attribute density
331
+ # (40-attr elements list ~7x faster than the chain).
332
+ def attribute_rows_native
333
+ ::Leptris::XML::Native.attribute_rows(@document, @c_address)
334
+ .each_slice(3)
335
+ .map do |name, value, handle|
336
+ ::Leptris::XML::Attr.new(name, value, self,
337
+ c_handle: ::FFI::Pointer.new(handle))
338
+ end
339
+ end
340
+
341
+ NATIVE_ATTR_ROWS =
342
+ defined?(::Leptris::XML::Native) &&
343
+ ::Leptris::XML::Native.respond_to?(:attribute_rows)
344
+ private_constant :NATIVE_ATTR_ROWS
345
+
322
346
  # The element's own namespace prefix (e.g. "foo" for <foo:child/>),
323
347
  # or nil when the element has none.
324
348
  def prefix
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leptris
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.222.1
4
+ version: 1.9.222.2
5
5
  platform: x86_64-linux
6
6
  authors:
7
7
  - Ribose Inc.