| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4347bd2 commit d87f9af
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -57,6 +57,7 @@ using v8::ArrayBufferView; | |||
| 57 | 57 | using v8::BackingStore; | |
| 58 | 58 | using v8::Context; | |
| 59 | 59 | using v8::EscapableHandleScope; | |
| 60 | + using v8::FastApiTypedArray; | ||
| 60 | 61 | using v8::FunctionCallbackInfo; | |
| 61 | 62 | using v8::Global; | |
| 62 | 63 | using v8::HandleScope; | |
@@ -843,6 +844,23 @@ void Compare(const FunctionCallbackInfo<Value> &args) { | |||
| 843 | 844 | args.GetReturnValue().Set(val); | |
| 844 | 845 | } | |
| 845 | 846 | ||
| 847 | + int32_t FastCompare(v8::Local<v8::Value>, | ||
| 848 | + const FastApiTypedArray<uint8_t>& a, | ||
| 849 | + const FastApiTypedArray<uint8_t>& b) { | ||
| 850 | + uint8_t* data_a; | ||
| 851 | + uint8_t* data_b; | ||
| 852 | + CHECK(a.getStorageIfAligned(&data_a)); | ||
| 853 | + CHECK(b.getStorageIfAligned(&data_b)); | ||
| 854 | + | ||
| 855 | + size_t cmp_length = std::min(a.length(), b.length()); | ||
| 856 | + | ||
| 857 | + return normalizeCompareVal( | ||
| 858 | + cmp_length > 0 ? memcmp(data_a, data_b, cmp_length) : 0, | ||
| 859 | + a.length(), | ||
| 860 | + b.length()); | ||
| 861 | + } | ||
| 862 | + | ||
| 863 | + static v8::CFunction fast_compare(v8::CFunction::Make(FastCompare)); | ||
| 846 | 864 | ||
| 847 | 865 | // Computes the offset for starting an indexOf or lastIndexOf search. | |
| 848 | 866 | // Returns either a valid offset in [0...<length - 1>], ie inside the Buffer, | |
@@ -1409,7 +1427,7 @@ void Initialize(Local<Object> target, | |||
| 1409 | 1427 | SlowByteLengthUtf8, | |
| 1410 | 1428 | &fast_byte_length_utf8); | |
| 1411 | 1429 | SetMethod(context, target, "copy", Copy); | |
| 1412 | - SetMethodNoSideEffect(context, target, "compare", Compare); | ||
| 1430 | + SetFastMethodNoSideEffect(context, target, "compare", Compare, &fast_compare); | ||
| 1413 | 1431 | SetMethodNoSideEffect(context, target, "compareOffset", CompareOffset); | |
| 1414 | 1432 | SetMethod(context, target, "fill", Fill); | |
| 1415 | 1433 | SetMethodNoSideEffect(context, target, "indexOfBuffer", IndexOfBuffer); | |
@@ -1469,6 +1487,8 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { | |||
| 1469 | 1487 | registry->Register(FastByteLengthUtf8); | |
| 1470 | 1488 | registry->Register(Copy); | |
| 1471 | 1489 | registry->Register(Compare); | |
| 1490 | + registry->Register(FastCompare); | ||
| 1491 | + registry->Register(fast_compare.GetTypeInfo()); | ||
| 1472 | 1492 | registry->Register(CompareOffset); | |
| 1473 | 1493 | registry->Register(Fill); | |
| 1474 | 1494 | registry->Register(IndexOfBuffer); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,6 +27,10 @@ using CFunctionCallbackWithStrings = | |||
| 27 | 27 | bool (*)(v8::Local<v8::Value>, | |
| 28 | 28 | const v8::FastOneByteString& input, | |
| 29 | 29 | const v8::FastOneByteString& base); | |
| 30 | + using CFunctionCallbackWithTwoUint8Arrays = | ||
| 31 | + int32_t (*)(v8::Local<v8::Value>, | ||
| 32 | + const v8::FastApiTypedArray<uint8_t>&, | ||
| 33 | + const v8::FastApiTypedArray<uint8_t>&); | ||
| 30 | 34 | using CFunctionCallbackWithTwoUint8ArraysFallback = | |
| 31 | 35 | bool (*)(v8::Local<v8::Value>, | |
| 32 | 36 | const v8::FastApiTypedArray<uint8_t>&, | |
@@ -56,6 +60,7 @@ class ExternalReferenceRegistry { | |||
| 56 | 60 | V(CFunctionCallbackWithBool) \ | |
| 57 | 61 | V(CFunctionCallbackWithString) \ | |
| 58 | 62 | V(CFunctionCallbackWithStrings) \ | |
| 63 | + V(CFunctionCallbackWithTwoUint8Arrays) \ | ||
| 59 | 64 | V(CFunctionCallbackWithTwoUint8ArraysFallback) \ | |
| 60 | 65 | V(CFunctionWithUint32) \ | |
| 61 | 66 | V(CFunctionWithDoubleReturnDouble) \ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments