xrb 0.7.0 → 0.9.0

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: bd5f5866b9f16e578f765cb49940fa5f4b43f6421ce1efe187a2e6b56a150e58
4
- data.tar.gz: 51345868ef2d3e106f47a2927fb4c908331bc5fd3317f0d83a4aa65d49e9b253
3
+ metadata.gz: 262e952884557bc231200ca4a520519e9372d5c0aec682bbd92685258a16d115
4
+ data.tar.gz: c994e66e6a2c440f0e6ff36a5d964995081e17ab4c79792564d42862c306dc98
5
5
  SHA512:
6
- metadata.gz: efe42a5f52863f29a1383fdc2572b9aac8c870e4ce905a0d2b4426859bc9f4113697f0ea1450d2354accddc27c74e2df1944512400029f3c548743cde4da35ed
7
- data.tar.gz: a689741788594d7c11700fe92f5ef0f71a9bef88b2b4b15dd7df3483d05e6630cd99f9863b41901c6f10bf6a0ed3327fb46acad581dfbebb26d83a45926c5e2f
6
+ metadata.gz: 006b40e77f38cf875163408b443d7f55a5a464a9658ec812071db7aa196133335281cad0ae9c80f1badbdffe77914660b59592dc0d33b99323d91bae19bad9de
7
+ data.tar.gz: 8b3dcfb6bee297abfbd1dacf583aed9eddfc0ec61ec99840b9096dccad01446683095394305a44b7eb63e726abc23563bd4f085f39e62afa656aedf45c186961
checksums.yaml.gz.sig CHANGED
Binary file
data/ext/Makefile CHANGED
@@ -13,12 +13,12 @@ NULLCMD = :
13
13
  #### Start of system configuration section. ####
14
14
 
15
15
  srcdir = .
16
- topdir = /Users/samuel/.rubies/ruby-3.3.3/include/ruby-3.3.0
16
+ topdir = /Users/samuel/.rubies/ruby-3.3.4/include/ruby-3.3.0
17
17
  hdrdir = $(topdir)
18
- arch_hdrdir = /Users/samuel/.rubies/ruby-3.3.3/include/ruby-3.3.0/arm64-darwin23
18
+ arch_hdrdir = /Users/samuel/.rubies/ruby-3.3.4/include/ruby-3.3.0/arm64-darwin24
19
19
  PATH_SEPARATOR = :
20
20
  VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby:$(srcdir)/xrb
21
- prefix = $(DESTDIR)/Users/samuel/.rubies/ruby-3.3.3
21
+ prefix = $(DESTDIR)/Users/samuel/.rubies/ruby-3.3.4
22
22
  rubysitearchprefix = $(rubylibprefix)/$(sitearch)
23
23
  rubyarchprefix = $(rubylibprefix)/$(arch)
24
24
  rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
@@ -106,7 +106,7 @@ RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
106
106
  RUBYW_BASE_NAME = rubyw
107
107
  RUBY_BASE_NAME = ruby
108
108
 
109
- arch = arm64-darwin23
109
+ arch = arm64-darwin24
110
110
  sitearch = $(arch)
111
111
  ruby_version = 3.3.0
112
112
  ruby = $(bindir)/$(RUBY_BASE_NAME)
@@ -117,8 +117,8 @@ ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/backward.h $(hdrdir)/ruby/ruby.h
117
117
  RM = rm -f
118
118
  RM_RF = rm -fr
119
119
  RMDIRS = rmdir -p
120
- MAKEDIRS = /opt/local/bin/gmkdir -p
121
- INSTALL = /opt/local/bin/ginstall -c
120
+ MAKEDIRS = mkdir -p
121
+ INSTALL = /usr/bin/install -c
122
122
  INSTALL_PROG = $(INSTALL) -m 0755
123
123
  INSTALL_DATA = $(INSTALL) -m 644
124
124
  COPY = cp
Binary file
data/ext/escape.o CHANGED
Binary file
data/ext/markup.o CHANGED
Binary file
data/ext/query.o CHANGED
Binary file
data/ext/tag.o CHANGED
Binary file
data/ext/template.o CHANGED
Binary file
data/ext/xrb/escape.c CHANGED
@@ -103,38 +103,40 @@ VALUE XRB_Markup_append_string(VALUE buffer, VALUE string) {
103
103
  return XRB_Markup_append_buffer(buffer, s, p, end);
104
104
  }
105
105
 
106
- VALUE XRB_Markup_append_slow(VALUE self, VALUE buffer, VALUE value) {
107
- if (value == Qnil) return Qnil;
106
+ VALUE XRB_Markup_append_slow(VALUE self, VALUE output, VALUE value) {
107
+ // if (value == Qnil) return Qnil;
108
108
 
109
109
  if (!XRB_Markup_is_markup(value)) {
110
+ value = rb_funcall(value, id_to_s, 0);
110
111
  value = XRB_Markup_escape_string(Qnil, value);
111
112
  }
112
-
113
- rb_funcall(buffer, id_concat, 1, value);
114
113
 
115
- return buffer;
114
+ rb_funcall(output, id_concat, 1, value);
115
+
116
+ return output;
116
117
  }
117
118
 
118
- VALUE XRB_Markup_append(VALUE self, VALUE buffer, VALUE value) {
119
+ VALUE XRB_Markup_append(VALUE self, VALUE output, VALUE value) {
119
120
  if (value == Qnil) return Qnil;
120
121
 
121
- if (RB_TYPE_P(buffer, T_STRING)) {
122
- rb_str_modify(buffer);
122
+ if (RB_TYPE_P(output, T_STRING)) {
123
+ rb_str_modify(output);
123
124
  } else {
124
- return XRB_Markup_append_slow(self, buffer, value);
125
+ return XRB_Markup_append_slow(self, output, value);
125
126
  }
126
127
 
128
+ // The output buffer is a string, so we can append directly:
127
129
  if (XRB_Markup_is_markup(value)) {
128
- rb_str_append(buffer, value);
130
+ rb_str_append(output, value);
129
131
  } else {
130
132
  if (rb_type(value) != T_STRING) {
131
133
  value = rb_funcall(value, id_to_s, 0);
132
134
  }
133
135
 
134
- XRB_Markup_append_string(buffer, value);
136
+ XRB_Markup_append_string(output, value);
135
137
  }
136
138
 
137
- return buffer;
139
+ return output;
138
140
  }
139
141
 
140
142
  // Convert markup special characters to entities. May return the original string if no changes were made.
data/ext/xrb/tag.c CHANGED
@@ -50,7 +50,7 @@ inline static VALUE XRB_Tag_prefix_key(VALUE prefix, VALUE key) {
50
50
  return buffer;
51
51
  }
52
52
 
53
- VALUE XRB_Tag_append_attributes(VALUE self, VALUE buffer, VALUE attributes, VALUE prefix);
53
+ VALUE XRB_Tag_append_attributes_string(VALUE self, VALUE buffer, VALUE attributes, VALUE prefix);
54
54
 
55
55
  static void XRB_Tag_append_tag_attribute(VALUE buffer, VALUE key, VALUE value, VALUE prefix) {
56
56
  // We skip over attributes with nil value:
@@ -60,7 +60,7 @@ static void XRB_Tag_append_tag_attribute(VALUE buffer, VALUE key, VALUE value, V
60
60
  key = XRB_Tag_prefix_key(prefix, key);
61
61
 
62
62
  if (XRB_Tag_valid_attributes(value)) {
63
- XRB_Tag_append_attributes(Qnil, buffer, value, key);
63
+ XRB_Tag_append_attributes_string(Qnil, buffer, value, key);
64
64
  } else {
65
65
  rb_str_cat_cstr(buffer, " ");
66
66
  rb_str_append(buffer, key);
@@ -73,24 +73,24 @@ static void XRB_Tag_append_tag_attribute(VALUE buffer, VALUE key, VALUE value, V
73
73
  }
74
74
  }
75
75
 
76
- typedef struct {
76
+ struct XRB_Tag_Append_Tag_Attribute_Argument {
77
77
  VALUE buffer;
78
78
  VALUE prefix;
79
- } XRB_Tag_Accumulation;
79
+ };
80
80
 
81
81
  static int XRB_Tag_append_tag_attribute_foreach(VALUE key, VALUE value, VALUE _argument) {
82
- XRB_Tag_Accumulation * argument = (XRB_Tag_Accumulation *)_argument;
82
+ struct XRB_Tag_Append_Tag_Attribute_Argument * argument = (struct XRB_Tag_Append_Tag_Attribute_Argument *)_argument;
83
83
 
84
84
  XRB_Tag_append_tag_attribute(argument->buffer, key, value, argument->prefix);
85
85
 
86
86
  return ST_CONTINUE;
87
87
  }
88
88
 
89
- VALUE XRB_Tag_append_attributes(VALUE self, VALUE buffer, VALUE attributes, VALUE prefix) {
89
+ VALUE XRB_Tag_append_attributes_string(VALUE self, VALUE buffer, VALUE attributes, VALUE prefix) {
90
90
  int type = rb_type(attributes);
91
91
 
92
92
  if (type == T_HASH) {
93
- XRB_Tag_Accumulation argument = {buffer, prefix};
93
+ struct XRB_Tag_Append_Tag_Attribute_Argument argument = {buffer, prefix};
94
94
  rb_hash_foreach(attributes, &XRB_Tag_append_tag_attribute_foreach, (VALUE)&argument);
95
95
  } else if (type == T_ARRAY) {
96
96
  long i;
@@ -114,13 +114,45 @@ VALUE XRB_Tag_append_attributes(VALUE self, VALUE buffer, VALUE attributes, VALU
114
114
  return Qnil;
115
115
  }
116
116
 
117
- VALUE XRB_Tag_append_tag(VALUE self, VALUE buffer, VALUE name, VALUE attributes, VALUE content) {
117
+ static size_t XRB_Tag_estimate_attributes_size(VALUE attributes, VALUE prefix) {
118
+ if (attributes == Qnil) return 0;
119
+
120
+ int type = rb_type(attributes);
121
+
122
+ if (type == T_HASH) {
123
+ return rb_hash_size(attributes) * 32;
124
+ } else if (type == T_ARRAY) {
125
+ return RARRAY_LEN(attributes) * 32;
126
+ }
127
+
128
+ return 0;
129
+ }
130
+
131
+ VALUE XRB_Tag_append_attributes(VALUE self, VALUE output, VALUE attributes, VALUE prefix) {
132
+ size_t estimated_size = XRB_Tag_estimate_attributes_size(attributes, prefix);
133
+
134
+ // If there are no attributes, we return early:
135
+ if (estimated_size == 0) return Qnil;
136
+
137
+ if (rb_type(output) == T_STRING) {
138
+ rb_str_modify_expand(output, estimated_size);
139
+ XRB_Tag_append_attributes_string(self, output, attributes, prefix);
140
+ } else {
141
+ VALUE buffer = rb_str_buf_new(estimated_size);
142
+ XRB_Tag_append_attributes_string(self, buffer, attributes, prefix);
143
+ rb_funcall(output, id_concat, 1, buffer);
144
+ }
145
+
146
+ return Qnil;
147
+ }
148
+
149
+ VALUE XRB_Tag_append_tag_string(VALUE self, VALUE buffer, VALUE name, VALUE attributes, VALUE content) {
118
150
  StringValue(name);
119
151
 
120
152
  rb_str_cat_cstr(buffer, "<");
121
153
  rb_str_buf_append(buffer, name);
122
154
 
123
- XRB_Tag_append_attributes(self, buffer, attributes, Qnil);
155
+ XRB_Tag_append_attributes_string(self, buffer, attributes, Qnil);
124
156
 
125
157
  if (content == Qnil || content == Qfalse) {
126
158
  rb_str_cat_cstr(buffer, "/>");
@@ -139,30 +171,46 @@ VALUE XRB_Tag_append_tag(VALUE self, VALUE buffer, VALUE name, VALUE attributes,
139
171
  return Qnil;
140
172
  }
141
173
 
142
- VALUE XRB_Tag_format_tag(VALUE self, VALUE name, VALUE attributes, VALUE content) {
143
- rb_encoding *encoding = rb_enc_get(name);
174
+ static size_t XRB_Tag_estimate_size(VALUE name, VALUE attributes, VALUE content) {
175
+ size_t estimated_size = (RSTRING_LEN(name) * 2) + XRB_Tag_estimate_attributes_size(attributes, Qnil) + 5;
144
176
 
145
- VALUE buffer = rb_enc_str_new(0, 0, encoding);
146
- rb_str_modify_expand(buffer, 256);
147
-
148
- XRB_Tag_append_tag(self, buffer, name, attributes, content);
177
+ if (rb_type(content) == T_STRING) {
178
+ estimated_size += RSTRING_LEN(content);
179
+ }
149
180
 
150
- return buffer;
181
+ return estimated_size;
151
182
  }
152
183
 
153
- VALUE XRB_Tag_write_opening_tag(VALUE self, VALUE buffer) {
154
- VALUE name = rb_struct_getmember(self, id_name);
155
- VALUE attributes = rb_struct_getmember(self, id_attributes);
156
- VALUE closed = rb_struct_getmember(self, id_closed);
184
+ VALUE XRB_Tag_append_tag(VALUE self, VALUE output, VALUE name, VALUE attributes, VALUE content) {
185
+ size_t estimated_size = XRB_Tag_estimate_size(name, attributes, content);
186
+
187
+ if (rb_type(output) == T_STRING) {
188
+ rb_str_modify_expand(output, estimated_size);
189
+ XRB_Tag_append_tag_string(self, output, name, attributes, content);
190
+ } else {
191
+ VALUE buffer = rb_str_buf_new(estimated_size);
192
+ XRB_Tag_append_tag_string(self, buffer, name, attributes, content);
193
+ rb_funcall(output, id_concat, 1, buffer);
194
+ }
195
+
196
+ return Qnil;
197
+ }
157
198
 
158
- StringValue(name);
199
+ VALUE XRB_Tag_format_tag(VALUE self, VALUE name, VALUE attributes, VALUE content) {
200
+ size_t estimated_size = XRB_Tag_estimate_size(name, attributes, content);
159
201
 
160
- rb_str_modify_expand(buffer, RSTRING_LEN(name) + 256);
202
+ VALUE buffer = rb_str_buf_new(estimated_size);
161
203
 
204
+ XRB_Tag_append_tag_string(self, buffer, name, attributes, content);
205
+
206
+ return buffer;
207
+ }
208
+
209
+ VALUE XRB_Tag_write_opening_tag_string(VALUE self, VALUE buffer, VALUE name, VALUE attributes, VALUE closed) {
162
210
  rb_str_cat_cstr(buffer, "<");
163
211
  rb_str_buf_append(buffer, name);
164
212
 
165
- XRB_Tag_append_attributes(self, buffer, attributes, Qnil);
213
+ XRB_Tag_append_attributes_string(self, buffer, attributes, Qnil);
166
214
 
167
215
  if (closed == Qtrue) {
168
216
  rb_str_cat_cstr(buffer, "/>");
@@ -173,17 +221,52 @@ VALUE XRB_Tag_write_opening_tag(VALUE self, VALUE buffer) {
173
221
  return Qnil;
174
222
  }
175
223
 
176
- VALUE XRB_Tag_write_closing_tag(VALUE self, VALUE buffer) {
224
+ VALUE XRB_Tag_write_opening_tag(VALUE self, VALUE output) {
177
225
  VALUE name = rb_struct_getmember(self, id_name);
178
-
179
226
  StringValue(name);
180
227
 
181
- rb_str_modify_expand(buffer, RSTRING_LEN(name) + 3);
228
+ VALUE attributes = rb_struct_getmember(self, id_attributes);
229
+ VALUE closed = rb_struct_getmember(self, id_closed);
230
+
231
+ // The size of the tag name + attributes + at most 3 characters for the closing tag symbols.
232
+ size_t estimated_size = RSTRING_LEN(name) + XRB_Tag_estimate_attributes_size(attributes, Qnil) + 3;
233
+
234
+ if (rb_type(output) == T_STRING) {
235
+ rb_str_modify_expand(output, estimated_size);
236
+ XRB_Tag_write_opening_tag_string(self, output, name, attributes, closed);
237
+ } else {
238
+ VALUE buffer = rb_str_buf_new(estimated_size);
239
+ XRB_Tag_write_opening_tag_string(self, buffer, name, attributes, closed);
240
+ rb_funcall(output, id_concat, 1, buffer);
241
+ }
182
242
 
243
+ return Qnil;
244
+ }
245
+
246
+ VALUE XRB_Tag_write_closing_tag_string(VALUE self, VALUE buffer, VALUE name) {
183
247
  rb_str_cat_cstr(buffer, "</");
184
248
  rb_str_buf_append(buffer, name);
185
249
  rb_str_cat_cstr(buffer, ">");
186
250
 
251
+ return buffer;
252
+ }
253
+
254
+ VALUE XRB_Tag_write_closing_tag(VALUE self, VALUE output) {
255
+ VALUE name = rb_struct_getmember(self, id_name);
256
+ StringValue(name);
257
+
258
+ // The size of the tag name + 3 characters for the closing tag symbols.
259
+ size_t estimated_size = RSTRING_LEN(name) + 3;
260
+
261
+ if (rb_type(output) == T_STRING) {
262
+ rb_str_modify_expand(output, estimated_size);
263
+ XRB_Tag_write_closing_tag_string(self, output, name);
264
+ } else {
265
+ VALUE buffer = rb_str_buf_new(estimated_size);
266
+ XRB_Tag_write_closing_tag_string(self, buffer, name);
267
+ rb_funcall(output, id_concat, 1, buffer);
268
+ }
269
+
187
270
  return Qnil;
188
271
  }
189
272