@nxtedition/rocksdb 11.1.2 → 11.1.4

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.
package/binding.cc CHANGED
@@ -1487,17 +1487,22 @@ NAPI_METHOD(regex_init) {
1487
1487
  std::string pattern;
1488
1488
  NAPI_STATUS_THROWS(GetString(env, argv[0], pattern));
1489
1489
 
1490
- auto batch = std::make_unique<std::regex>(pattern, std::regex::optimize | std::regex::ECMAScript);
1490
+ try {
1491
+ auto regex = std::make_unique<std::regex>(pattern, std::regex::optimize | std::regex::ECMAScript);
1491
1492
 
1492
- napi_value result;
1493
- NAPI_STATUS_THROWS(napi_create_external(env, batch.get(), Finalize<std::regex>, batch.get(), &result));
1494
- batch.release();
1493
+ napi_value result;
1494
+ NAPI_STATUS_THROWS(napi_create_external(env, regex.get(), Finalize<std::regex>, regex.get(), &result));
1495
+ regex.release();
1495
1496
 
1496
- return result;
1497
+ return result;
1498
+ } catch (const std::exception& e) {
1499
+ napi_throw_error(env, nullptr, e.what());
1500
+ return 0;
1501
+ }
1497
1502
  }
1498
1503
 
1499
1504
  NAPI_METHOD(regex_test) {
1500
- NAPI_ARGV(2);
1505
+ NAPI_ARGV(4);
1501
1506
 
1502
1507
  std::regex* regex;
1503
1508
  NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&regex)));
@@ -1505,12 +1510,25 @@ NAPI_METHOD(regex_test) {
1505
1510
  rocksdb::Slice value;
1506
1511
  NAPI_STATUS_THROWS(GetValue(env, argv[1], value));
1507
1512
 
1508
- const bool match = std::regex_search(value.data(), value.data() + value.size(), *regex);
1513
+ int offset = 0;
1514
+ NAPI_STATUS_THROWS(GetValue(env, argv[2], offset));
1515
+ offset = std::max(0, std::min<int>(offset, value.size()));
1509
1516
 
1510
- napi_value result;
1511
- NAPI_STATUS_THROWS(napi_get_boolean(env, match, &result));
1517
+ int length = 0;
1518
+ NAPI_STATUS_THROWS(GetValue(env, argv[3], length));
1519
+ length = std::max(0, std::min<int>(length, value.size() - offset));
1512
1520
 
1513
- return result;
1521
+ try {
1522
+ const bool match = std::regex_search(value.data() + offset, value.data() + offset + length, *regex);
1523
+
1524
+ napi_value result;
1525
+ NAPI_STATUS_THROWS(napi_get_boolean(env, match, &result));
1526
+
1527
+ return result;
1528
+ } catch (const std::exception& e) {
1529
+ napi_throw_error(env, nullptr, e.what());
1530
+ return 0;
1531
+ }
1514
1532
  }
1515
1533
 
1516
1534
  NAPI_METHOD(regex_test_many) {
@@ -1525,22 +1543,27 @@ NAPI_METHOD(regex_test_many) {
1525
1543
  napi_value result;
1526
1544
  NAPI_STATUS_THROWS(napi_create_array_with_length(env, count, &result));
1527
1545
 
1528
- for (uint32_t n = 0; n < count; n++) {
1529
- napi_value valueElement;
1530
- NAPI_STATUS_THROWS(napi_get_element(env, argv[1], n, &valueElement));
1546
+ try {
1547
+ for (uint32_t n = 0; n < count; n++) {
1548
+ napi_value valueElement;
1549
+ NAPI_STATUS_THROWS(napi_get_element(env, argv[1], n, &valueElement));
1531
1550
 
1532
- rocksdb::Slice value;
1533
- NAPI_STATUS_THROWS(GetValue(env, valueElement, value));
1551
+ rocksdb::Slice value;
1552
+ NAPI_STATUS_THROWS(GetValue(env, valueElement, value));
1534
1553
 
1535
- const bool match = std::regex_search(value.data(), value.data() + value.size(), *regex);
1554
+ const bool match = std::regex_search(value.data(), value.data() + value.size(), *regex);
1536
1555
 
1537
- napi_value matchElement;
1538
- NAPI_STATUS_THROWS(napi_get_boolean(env, match, &matchElement));
1556
+ napi_value matchElement;
1557
+ NAPI_STATUS_THROWS(napi_get_boolean(env, match, &matchElement));
1539
1558
 
1540
- NAPI_STATUS_THROWS(napi_set_element(env, result, n, matchElement));
1541
- }
1559
+ NAPI_STATUS_THROWS(napi_set_element(env, result, n, matchElement));
1560
+ }
1542
1561
 
1543
- return result;
1562
+ return result;
1563
+ } catch (const std::exception& e) {
1564
+ napi_throw_error(env, nullptr, e.what());
1565
+ return 0;
1566
+ }
1544
1567
  }
1545
1568
 
1546
1569
 
@@ -71,10 +71,10 @@
71
71
  "-momit-leaf-frame-pointer",
72
72
  "-fno-builtin-memcmp"
73
73
  ],
74
- "cflags": ["-std=c++20"],
74
+ "cflags": ["-std=c++20", "-march=znver1"],
75
75
  "cflags!": ["-fno-rtti"],
76
76
  "cflags_cc!": ["-fno-rtti"],
77
- "cflags_cc+": ["-frtti"]
77
+ "cflags_cc+": ["-frtti", '-march=znver1']
78
78
  }
79
79
  ],
80
80
  [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/rocksdb",
3
- "version": "11.1.2",
3
+ "version": "11.1.4",
4
4
  "description": "A low-level Node.js RocksDB binding",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
package/regex.js CHANGED
@@ -9,8 +9,16 @@ class Regex {
9
9
  this.#context = binding.regex_init(pattern)
10
10
  }
11
11
 
12
- test (value) {
13
- return binding.regex_test(this.#context, value)
12
+ test (buffer, byteOffset, byteLength) {
13
+ if (byteOffset === undefined) {
14
+ byteOffset = 0
15
+ }
16
+
17
+ if (byteLength === undefined) {
18
+ byteLength = buffer.byteLength - byteOffset
19
+ }
20
+
21
+ return binding.regex_test(this.#context, buffer, byteOffset, byteLength)
14
22
  }
15
23
 
16
24
  testMany (values) {