bare-buffer 1.2.9 → 2.0.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.
Files changed (3) hide show
  1. package/binding.c +12 -4
  2. package/binding.js +1 -1
  3. package/package.json +1 -1
package/binding.c CHANGED
@@ -36,7 +36,17 @@ bare_buffer_set_zero_fill_enabled (js_env_t *env, js_callback_info_t *info) {
36
36
 
37
37
  static uint32_t
38
38
  bare_buffer_byte_length_utf8_fast (js_ffi_receiver_t *receiver, js_ffi_string_t *str) {
39
- return str->len;
39
+ const uint8_t *data = (const uint8_t *) str->data;
40
+
41
+ uint32_t len = 0;
42
+
43
+ for (uint32_t i = 0, n = str->len; i < n; i++) {
44
+ // The string data is latin1 so we add an additional byte count for all
45
+ // non-ASCII characters.
46
+ len += 1 + (data[i] >> 7);
47
+ }
48
+
49
+ return len;
40
50
  }
41
51
 
42
52
  static js_value_t *
@@ -395,10 +405,8 @@ init (js_env_t *env, js_value_t *exports) {
395
405
  js_ffi_function_t *ffi;
396
406
  js_ffi_create_function(bare_buffer_byte_length_utf8_fast, function_info, &ffi);
397
407
 
398
- (void) ffi; // TODO Renable fast path for byte length
399
-
400
408
  js_value_t *val;
401
- js_create_function(env, "byteLengthUTF8", -1, bare_buffer_byte_length_utf8, NULL, &val);
409
+ js_create_function_with_ffi(env, "byteLengthUTF8", -1, bare_buffer_byte_length_utf8, NULL, ffi, &val);
402
410
  js_set_named_property(env, exports, "byteLengthUTF8", val);
403
411
  }
404
412
  {
package/binding.js CHANGED
@@ -1 +1 @@
1
- module.exports = process.addon(__dirname)
1
+ module.exports = require.addon()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-buffer",
3
- "version": "1.2.9",
3
+ "version": "2.0.0",
4
4
  "description": "Native buffers for JavaScript",
5
5
  "main": "index.js",
6
6
  "files": [