react-native-xxhash 0.1.4 → 0.1.6
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/cpp/react-native-xxhash.cpp +7 -7
- package/cpp/react-native-xxhash.h +12 -28
- package/ios/Xxhash.mm +14 -10
- package/package.json +1 -1
|
@@ -8,16 +8,16 @@ void xxhash::install(jsi::Runtime* rt_ptr) {
|
|
|
8
8
|
[](jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args,
|
|
9
9
|
size_t count) {
|
|
10
10
|
const jsi::Value& arg = args[0];
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
if (!arg.isString()) [[unlikely]] {
|
|
13
13
|
throw jsi::JSError(rt, "Argument is not a 'string'");
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
char result[33];
|
|
17
17
|
|
|
18
|
-
xxhash::
|
|
18
|
+
xxhash::make_hash_128(arg.asString(rt).utf8(rt), result);
|
|
19
19
|
|
|
20
|
-
return jsi::String::createFromUtf8(rt,
|
|
20
|
+
return jsi::String::createFromUtf8(rt, result);
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
jsi::Function hash64 = jsi::Function::createFromHostFunction(
|
|
@@ -30,11 +30,11 @@ void xxhash::install(jsi::Runtime* rt_ptr) {
|
|
|
30
30
|
throw jsi::JSError(rt, "Argument is not a 'string'");
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
char result[17];
|
|
34
34
|
|
|
35
|
-
xxhash::
|
|
35
|
+
xxhash::make_hash_64(arg.asString(rt).utf8(rt), result);
|
|
36
36
|
|
|
37
|
-
return jsi::String::createFromUtf8(rt,
|
|
37
|
+
return jsi::String::createFromUtf8(rt, result);
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
runtime.global().setProperty(runtime, "__xxhash128", std::move(hash128));
|
|
@@ -2,42 +2,26 @@
|
|
|
2
2
|
#ifndef XXHASH_H
|
|
3
3
|
#define XXHASH_H
|
|
4
4
|
#include <jsi/jsi.h>
|
|
5
|
-
#include "xxhash.h"
|
|
6
5
|
#include <iomanip>
|
|
7
6
|
#include <sstream>
|
|
7
|
+
#include "xxhash.h"
|
|
8
8
|
|
|
9
9
|
using namespace facebook;
|
|
10
10
|
|
|
11
11
|
namespace xxhash {
|
|
12
|
-
enum class HashSize {
|
|
13
|
-
BITS_64,
|
|
14
|
-
BITS_128,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
template <HashSize T>
|
|
18
|
-
inline void make_hash(const std::string_view str, std::stringstream& ss) noexcept;
|
|
19
|
-
|
|
20
|
-
template <>
|
|
21
|
-
inline void make_hash<HashSize::BITS_64>(const std::string_view str,
|
|
22
|
-
std::stringstream& ss) noexcept {
|
|
23
|
-
XXH64_hash_t hash = XXH3_64bits(str.data(), str.size());
|
|
24
|
-
|
|
25
|
-
ss << std::hex << std::setfill('0') << std::setw(16) << hash;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
template <>
|
|
29
|
-
inline void make_hash<HashSize::BITS_128>(const std::string_view str,
|
|
30
|
-
std::stringstream& ss) noexcept {
|
|
31
|
-
XXH128_hash_t hash = XXH3_128bits(str.data(), str.size());
|
|
32
|
-
|
|
33
|
-
ss << std::hex << std::setfill('0') << std::setw(16) << hash.high64
|
|
34
|
-
<< std::setw(16) << hash.low64;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
void install(jsi::Runtime* rt);
|
|
38
|
-
}
|
|
39
12
|
|
|
13
|
+
inline void make_hash_64(const std::string_view str, char result[17]) noexcept {
|
|
14
|
+
XXH64_hash_t hash = XXH3_64bits(str.data(), str.size());
|
|
15
|
+
std::snprintf(result, 17, "%016llx", hash);
|
|
16
|
+
};
|
|
40
17
|
|
|
18
|
+
inline void make_hash_128(const std::string_view str,
|
|
19
|
+
char result[33]) noexcept {
|
|
20
|
+
XXH128_hash_t hash = XXH3_128bits(str.data(), str.size());
|
|
21
|
+
std::snprintf(result, 33, "%016llx%016llx", hash.high64, hash.low64);
|
|
22
|
+
};
|
|
41
23
|
|
|
24
|
+
void install(jsi::Runtime* rt);
|
|
25
|
+
} // namespace xxhash
|
|
42
26
|
|
|
43
27
|
#endif /* XXHASH_H */
|
package/ios/Xxhash.mm
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
#import <jsi/jsi.h>
|
|
7
7
|
|
|
8
8
|
@implementation Xxhash
|
|
9
|
-
RCT_EXPORT_MODULE()
|
|
9
|
+
RCT_EXPORT_MODULE(xxhash)
|
|
10
10
|
|
|
11
11
|
@synthesize bridge = _bridge;
|
|
12
12
|
@synthesize methodQueue = _methodQueue;
|
|
@@ -15,20 +15,24 @@ RCT_EXPORT_MODULE()
|
|
|
15
15
|
return YES;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install){
|
|
19
|
+
NSLog(@"Installing JSI bindings for xxhash ...");
|
|
20
|
+
RCTBridge* bridge = [RCTBridge currentBridge];
|
|
21
|
+
RCTCxxBridge* cxxBridge = (RCTCxxBridge*)bridge;
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
if (cxxBridge == nil) {
|
|
24
|
+
return @false;
|
|
25
|
+
}
|
|
21
26
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
auto jsiRuntime = (jsi::Runtime*) cxxBridge.runtime;
|
|
28
|
+
if (jsiRuntime == nil) {
|
|
29
|
+
return @false;
|
|
30
|
+
}
|
|
26
31
|
|
|
27
|
-
|
|
32
|
+
xxhash::install(jsiRuntime);
|
|
28
33
|
|
|
29
|
-
|
|
34
|
+
return @true;
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
|
|
33
|
-
|
|
34
38
|
@end
|