leptris 1.9.222.1 → 1.9.222.2
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 +4 -4
- data/ext/leptris/native/native.c +30 -0
- data/lib/leptris/version.rb +1 -1
- data/lib/leptris/xml/element.rb +25 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bded827a8ed4a8dcac8efcda8a391e79b497c122c57b65115027025b406c027b
|
|
4
|
+
data.tar.gz: 7171d06a07b227717f12de2a2bcccaabefce5067fb0d49d6632f1010b65fdb31
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1055292d2190857575b0858cc61a2f1db481324c6ea56097894131a19bf43b360b72db03de87c908e3e071c6f68d71e4a973134580d40619f82ed772b7f106a6
|
|
7
|
+
data.tar.gz: 402c643195961c7159f6af522b8cac0f5366ca1a44ea94490ff69482b6311ab912fbae23044997af721544a0b0810fb37d8a6f2e9048c24e58086295d3b13965
|
data/ext/leptris/native/native.c
CHANGED
|
@@ -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",
|
data/lib/leptris/version.rb
CHANGED
data/lib/leptris/xml/element.rb
CHANGED
|
@@ -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 =
|
|
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
|