leptris 1.9.199.0 → 1.9.199.1

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: b7317a3a059f59af92c730eda04a9793104d627f4929db5298756be47f318817
4
- data.tar.gz: 121b3049b4be8b70aa1e6244f2140f351039794ea04a0bf1f09e40a23f366453
3
+ metadata.gz: bea70279fbfb8a49550bb7ce0782437960861749683fa0df0bcaee0064830b6d
4
+ data.tar.gz: 1ba8dede4c87e93e8812154daef28eed7f4d4544e83534e14f913279ec0316ba
5
5
  SHA512:
6
- metadata.gz: a4dd3fb633b04367c5099f43c9d2b1d6531bc790bb1aa93bc0e273d6232409e780d71e458d76129992f74cb8e5522959b14636f0d74855570d242fba086c93c5
7
- data.tar.gz: 6fdbbe9dc7e1b92c06774fd92413989574c6505f102e086d4a9919bac76cf80432b688fe94347a7404f29af26808ccd2a4f756d0afa5da3fcd165ce8294e3093
6
+ metadata.gz: 780cc666ddd610cdddcb277b1fd4b0c65f460158053772f406d387a48e97ec4d4c917d22500ab356cf21f373605089d23f4e17a3828324a6c3fd943948ded044
7
+ data.tar.gz: 7103eb627d5df66e146486922725f4919b84668f619a75d4a3379668962cccb8bcb7d0798ac422ac94bdf11131b995b5d44ca4f887cee6c4aeb39e8a023467f8
@@ -1941,6 +1941,122 @@ static VALUE nf_snapshot_rows(VALUE self, VALUE document, VALUE addr)
1941
1941
  return out;
1942
1942
  }
1943
1943
 
1944
+ /* ---- Struct plan executor (moxml "miles faster" round) ------------
1945
+ * The consumer's shape compiles to spec: name (interned String) ->
1946
+ * [Struct class, attrs Hash (name -> slot Symbol), text slot Symbol
1947
+ * or nil, children slot Symbol or nil]. C walks the subtree
1948
+ * pre-order, mints typed structs directly (rb_struct_new +
1949
+ * rb_struct_aset), and attaches each to the nearest OPEN frame —
1950
+ * exactly Moxml::Plan's semantics: an unmatched element is a
1951
+ * barrier (its matched descendants surface at top level). Zero
1952
+ * Ruby frames and zero intermediate rows per element. */
1953
+ static void plan_walk(void *node, int depth, VALUE spec, VALUE stack,
1954
+ VALUE roots)
1955
+ {
1956
+ if (f_node_type(node) == WS_NODE_ELEMENT) {
1957
+ const char *name_c = f_elem_name(node);
1958
+ VALUE entry = name_c ? rb_hash_aref(spec,
1959
+ rb_enc_interned_str(name_c, strlen(name_c),
1960
+ rb_utf8_encoding()))
1961
+ : Qnil;
1962
+
1963
+ /* Complete deeper frames: pre-order means any open frame at
1964
+ * depth >= this element's depth belongs to an earlier
1965
+ * subtree that ended before this row. */
1966
+ while (RARRAY_LEN(stack) >= 2 &&
1967
+ NUM2INT(rb_ary_entry(stack, RARRAY_LEN(stack) - 2)) >=
1968
+ depth) {
1969
+ rb_ary_pop(stack);
1970
+ rb_ary_pop(stack);
1971
+ }
1972
+
1973
+ if (!NIL_P(entry)) {
1974
+ /* volatile: keep live VALUEs on the C stack so the
1975
+ * conservative scanner sees them on every ABI (windows
1976
+ * x64 keeps some only in callee-saved registers). */
1977
+ volatile VALUE klass = rb_ary_entry(entry, 0);
1978
+ volatile VALUE attrs_spec = rb_ary_entry(entry, 1);
1979
+ volatile VALUE text_slot = rb_ary_entry(entry, 2);
1980
+ volatile VALUE children_slot = rb_ary_entry(entry, 3);
1981
+ VALUE value = rb_struct_new(klass);
1982
+
1983
+ for (void *a = f_attr_first(node); a; a = f_attr_next(a)) {
1984
+ const char *an = f_attr_name(a);
1985
+ VALUE slot = an ? rb_hash_aref(attrs_spec,
1986
+ rb_enc_interned_str(an, strlen(an),
1987
+ rb_utf8_encoding()))
1988
+ : Qnil;
1989
+ if (!NIL_P(slot)) {
1990
+ const char *av = f_attr_value(node, a);
1991
+ rb_struct_aset(value, slot,
1992
+ av ? rb_utf8_str_new_cstr(av) : Qnil);
1993
+ }
1994
+ }
1995
+ if (!NIL_P(text_slot)) {
1996
+ void *c;
1997
+ for (c = f_first_child(node); c; c = f_next_sibling(c)) {
1998
+ if (f_node_type(c) == WS_NODE_TEXT) {
1999
+ const char *t = f_text_content(c);
2000
+ rb_struct_aset(value, text_slot,
2001
+ t ? rb_utf8_str_new_cstr(t) : Qnil);
2002
+ break;
2003
+ }
2004
+ }
2005
+ }
2006
+
2007
+ /* attach: nearest open frame carrying a children array;
2008
+ * barriers (unmatched ancestors) and the root surface
2009
+ * the value at top level — Moxml::Plan's contract. */
2010
+ if (RARRAY_LEN(stack) >= 2 &&
2011
+ rb_ary_entry(stack, RARRAY_LEN(stack) - 1) != Qnil) {
2012
+ rb_ary_push(rb_ary_entry(stack, RARRAY_LEN(stack) - 1),
2013
+ value);
2014
+ } else {
2015
+ rb_ary_push(roots, value);
2016
+ }
2017
+ RB_GC_GUARD(value);
2018
+ RB_GC_GUARD(entry);
2019
+
2020
+ if (!NIL_P(children_slot)) {
2021
+ VALUE children = rb_ary_new();
2022
+ rb_struct_aset(value, children_slot, children);
2023
+ rb_ary_push(stack, INT2NUM(depth));
2024
+ rb_ary_push(stack, children);
2025
+ }
2026
+ } else {
2027
+ /* unmatched: barrier frame — descendants must not
2028
+ * attach through it (Moxml::Plan parity). */
2029
+ rb_ary_push(stack, INT2NUM(depth));
2030
+ rb_ary_push(stack, Qnil);
2031
+ }
2032
+
2033
+ void *c;
2034
+ for (c = f_first_child(node); c; c = f_next_sibling(c)) {
2035
+ plan_walk(c, depth + 1, spec, stack, roots);
2036
+ }
2037
+ } else if (f_node_type(node) == WS_NODE_DOCTYPE ||
2038
+ f_node_type(node) == 9) {
2039
+ void *dc = f_first_child(node);
2040
+ while (dc) {
2041
+ plan_walk(dc, depth, spec, stack, roots);
2042
+ dc = f_next_sibling(dc);
2043
+ }
2044
+ }
2045
+ }
2046
+
2047
+ static VALUE nf_plan_structs(VALUE self, VALUE document, VALUE addr,
2048
+ VALUE spec)
2049
+ {
2050
+ (void)self;
2051
+ (void)document;
2052
+ VALUE roots = rb_ary_new();
2053
+ VALUE stack = rb_ary_new();
2054
+ plan_walk((void *)(uintptr_t)NUM2ULL(addr), 0, spec, stack, roots);
2055
+ RB_GC_GUARD(spec);
2056
+ RB_GC_GUARD(stack);
2057
+ return roots;
2058
+ }
2059
+
1944
2060
  /* ---- inner_html in one C pass (TODO.perf/18) --------------------
1945
2061
  * Serializes the receiver's children into one growable buffer:
1946
2062
  * elements via leptris_element_serialize_into (the same opts the
@@ -2490,6 +2606,8 @@ void Init_native(void)
2490
2606
  nf_snapshot_subtree, 2);
2491
2607
  rb_define_module_function(m_native, "snapshot_rows",
2492
2608
  nf_snapshot_rows, 2);
2609
+ rb_define_module_function(m_native, "plan_structs",
2610
+ nf_plan_structs, 3);
2493
2611
  rb_define_module_function(m_native, "doc_handle_attach",
2494
2612
  nf_doc_handle_attach, 1);
2495
2613
  rb_define_module_function(m_native, "doc_handle_release",
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Leptris
4
- VERSION = "1.9.199.0"
4
+ VERSION = "1.9.199.1"
5
5
  end
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.199.0
4
+ version: 1.9.199.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.