berns 4.1.0 → 4.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb2de0ba05a5e234fa5cef7edf3a222411222d0743c0e69492c1e1d5e53541bb
4
- data.tar.gz: f62f2273f787a46aa18784b668f1110adb80a1bbb8c33226c9c58e585d5acec7
3
+ metadata.gz: 9332f5ed53d3722052cc33ff3796a47555a50586e89512df69ac2f314dec592c
4
+ data.tar.gz: 381ebd539a72cb79925554928cb11503104beae42b3ec5f4566e973ac4647409
5
5
  SHA512:
6
- metadata.gz: 7d8fb46aeb4dc948729b36bbb6a794625618c34742ee2b18024d1cde99bda330b21bd7fb890bd241010a9b60e956c81fe401c3036464a90d28fb4ebca11ba621
7
- data.tar.gz: c7c430ae90da5be3b93f15d1ac6ab2bba300b89558cfb131af276b2af9d2e82b118fa0691000402bf7e982e13406defc275c786e2e512304041f660afe0b53cc
6
+ metadata.gz: 6001d1682311fffcddebb1d6cfefa7d9094386dae315d6d5b2d3a4a36a34ebdb97f9e5721c74b5f7dc4d8bfc1118fbf6c417f7bcc38f79c7158144729fe7909a
7
+ data.tar.gz: 7fce9c7ca12b3fec44c75902e3724ef6f4d6b11d77855e77864326bb4b1b3d8f53f47b45b99b59b70a37fe6f06199abf79cee317d2f28a0ff7931530f996cf87
data/README.org CHANGED
@@ -215,20 +215,22 @@ area base br col embed hr img input link menuitem meta param source track wbr
215
215
 
216
216
  ** Performance
217
217
 
218
- Berns 3 is about three times faster than the pure Ruby implementation used in
219
- version 2. See the file [[file:benchmarks/performance.rb][benchmarks/performance.rb]] for the benchmark code.
218
+ Berns 3 was a total rewrite from a pure Ruby implementation to one powered by a
219
+ C extension. That rewrite is about three times faster than the pure Ruby
220
+ implementation used in version 2. See the file [[file:benchmarks/performance.rb][benchmarks/performance.rb]] for the
221
+ benchmark code.
220
222
 
221
223
  #+begin_example
222
224
  Warming up --------------------------------------
223
- element 27.373k i/100ms
224
- berns 94.118k i/100ms
225
+ ruby 27.521k i/100ms
226
+ c-ext 74.915k i/100ms
225
227
  Calculating -------------------------------------
226
- element 314.078k4.5%) i/s - 1.588M in 5.065539s
227
- berns 935.528k6.1%) i/s - 4.706M in 5.049718s
228
+ ruby 275.913k1.0%) i/s - 1.404M in 5.087516s
229
+ c-ext 813.113k1.0%) i/s - 4.120M in 5.067902s
228
230
 
229
231
  Comparison:
230
- berns: 935527.9 i/s
231
- element: 314078.4 i/s - 2.98x (± 0.00) slower
232
+ c-ext: 813113.3 i/s
233
+ ruby: 275913.5 i/s - 2.95x (± 0.00) slower
232
234
  #+end_example
233
235
 
234
236
  ** Trivia
data/ext/berns/berns.c CHANGED
@@ -357,7 +357,20 @@ static char * hash_value_to_attribute(const char *attr, const size_t attrlen, VA
357
357
  free(combined);
358
358
  }
359
359
 
360
- return destination;
360
+ /*
361
+ * Reallocate destination to final size. This is generally a reduction in the
362
+ * allocated memory since we chunk allocations in 256 byte multiples.
363
+ */
364
+ char *rightsizeddest = realloc(destination, occupied + 1);
365
+
366
+ if (rightsizeddest == NULL) {
367
+ free(destination);
368
+ rb_raise(rb_eNoMemError, "Berns could not allocate sufficient memory.");
369
+ }
370
+
371
+ rightsizeddest[occupied] = '\0';
372
+
373
+ return rightsizeddest;
361
374
  }
362
375
 
363
376
  /*
@@ -452,6 +465,9 @@ static VALUE external_to_attributes(RB_UNUSED_VAR(VALUE self), VALUE attributes)
452
465
  return rstring;
453
466
  }
454
467
 
468
+ /*
469
+ * Create a void element i.e. one without children/content.
470
+ */
455
471
  static char * void_element(const char *tag, size_t tlen, VALUE attributes) {
456
472
  const char *empty = "";
457
473
  char *attrs = hash_value_to_attribute(empty, 0, attributes);
@@ -478,6 +494,8 @@ static char * void_element(const char *tag, size_t tlen, VALUE attributes) {
478
494
 
479
495
  ptr = stecpy(ptr, tag_close, end);
480
496
 
497
+ free(attrs);
498
+
481
499
  return dest;
482
500
  }
483
501
 
Binary file
data/lib/berns/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Berns
3
- VERSION = '4.1.0'
3
+ VERSION = '4.1.2'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berns
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Beck
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-06-14 00:00:00.000000000 Z
12
+ date: 2022-10-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A utility library for generating HTML strings.
15
15
  email: