MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / get_message

Method get_message

core/string/optimized_translation.cpp:219–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217}
218
219StringName OptimizedTranslation::get_message(const StringName &p_src_text, const StringName &p_context) const {
220 int htsize = hash_table.size();
221
222 if (htsize == 0) {
223 return StringName();
224 }
225
226 CharString str = p_src_text.operator String().utf8();
227 uint32_t h = hash(0, str.get_data());
228
229 const int *htr = hash_table.ptr();
230 const uint32_t *htptr = (const uint32_t *)&htr[0];
231 const int *btr = bucket_table.ptr();
232 const uint32_t *btptr = (const uint32_t *)&btr[0];
233 const uint8_t *sr = strings.ptr();
234 const char *sptr = (const char *)&sr[0];
235
236 uint32_t p = htptr[h % htsize];
237
238 if (p == 0xFFFFFFFF) {
239 return StringName(); //nothing
240 }
241
242 const Bucket &bucket = *(const Bucket *)&btptr[p];
243
244 h = hash(bucket.func, str.get_data());
245
246 int idx = -1;
247
248 for (int i = 0; i < bucket.size; i++) {
249 if (bucket.elem[i].key == h) {
250 idx = i;
251 break;
252 }
253 }
254
255 if (idx == -1) {
256 return StringName();
257 }
258
259 if (bucket.elem[idx].comp_size == bucket.elem[idx].uncomp_size) {
260 return String::utf8(&sptr[bucket.elem[idx].str_offset], bucket.elem[idx].uncomp_size);
261 } else {
262 CharString uncomp;
263 uncomp.resize_uninitialized(bucket.elem[idx].uncomp_size + 1);
264 smaz_decompress(&sptr[bucket.elem[idx].str_offset], bucket.elem[idx].comp_size, uncomp.ptrw(), bucket.elem[idx].uncomp_size);
265 return String::utf8(uncomp.get_data());
266 }
267}
268
269Vector<String> OptimizedTranslation::get_translated_message_list() const {
270 Vector<String> msgs;

Callers 1

generateMethod · 0.45

Calls 9

hashFunction · 0.85
StringNameClass · 0.70
sizeMethod · 0.65
utf8Method · 0.45
StringMethod · 0.45
get_dataMethod · 0.45
ptrMethod · 0.45
resize_uninitializedMethod · 0.45
ptrwMethod · 0.45

Tested by

no test coverage detected