-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathscript_byte_code.cc
35 lines (26 loc) · 936 Bytes
/
script_byte_code.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//---------------------------------------------------------------------------
#include "script_byte_code.h"
#include "mem.h"
#include "str.h"
//---------------------------------------------------------------------------
const uint8_t *
ScriptByteCode::FindStringOrReturnOriginal(const uint8_t *string) const {
const StenoScriptHashTable *hashTable = GetHashTable();
const size_t mask = hashTable->size - 1;
const size_t length = Str::Length(string);
size_t index = Crc32::Hash(string, length);
for (;;) {
const size_t textOffset = hashTable->offsets[index & mask];
if (textOffset == 0) {
return string;
}
const uint8_t *base = (const uint8_t *)this;
const uint8_t *candidate = base + textOffset;
if (Mem::Eq(string, candidate, length + 1)) {
return candidate;
}
++index;
}
return nullptr;
}
//---------------------------------------------------------------------------