| 51 | }; |
| 52 | |
| 53 | void OptimizedTranslation::generate(const Ref<Translation> &p_from) { |
| 54 | #ifdef TOOLS_ENABLED |
| 55 | ERR_FAIL_COND(p_from.is_null()); |
| 56 | List<StringName> keys; |
| 57 | p_from->get_message_list(&keys); |
| 58 | |
| 59 | int size = Math::larger_prime(keys.size()); |
| 60 | |
| 61 | Vector<Vector<Pair<int, CharString>>> buckets; |
| 62 | Vector<HashMap<uint32_t, int>> table; |
| 63 | Vector<uint32_t> hfunc_table; |
| 64 | Vector<CompressedString> compressed; |
| 65 | |
| 66 | table.resize(size); |
| 67 | hfunc_table.resize(size); |
| 68 | buckets.resize(size); |
| 69 | compressed.resize(keys.size()); |
| 70 | |
| 71 | int idx = 0; |
| 72 | int total_compression_size = 0; |
| 73 | |
| 74 | for (const StringName &E : keys) { |
| 75 | //hash string |
| 76 | CharString cs = E.operator String().utf8(); |
| 77 | uint32_t h = hash(0, cs.get_data()); |
| 78 | Pair<int, CharString> p; |
| 79 | p.first = idx; |
| 80 | p.second = cs; |
| 81 | buckets.write[h % size].push_back(p); |
| 82 | |
| 83 | //compress string |
| 84 | CharString src_s = p_from->get_message(E).operator String().utf8(); |
| 85 | CompressedString ps; |
| 86 | ps.orig_len = src_s.size(); |
| 87 | ps.offset = total_compression_size; |
| 88 | |
| 89 | if (ps.orig_len != 0) { |
| 90 | CharString dst_s; |
| 91 | dst_s.resize_uninitialized(src_s.size()); |
| 92 | int ret = smaz_compress(src_s.get_data(), src_s.size(), dst_s.ptrw(), src_s.size()); |
| 93 | if (ret >= src_s.size()) { |
| 94 | //if compressed is larger than original, just use original |
| 95 | ps.orig_len = src_s.size(); |
| 96 | ps.compressed = src_s; |
| 97 | } else { |
| 98 | dst_s.resize_uninitialized(ret); |
| 99 | //ps.orig_len=; |
| 100 | ps.compressed = dst_s; |
| 101 | } |
| 102 | } else { |
| 103 | ps.orig_len = 1; |
| 104 | ps.compressed.resize_uninitialized(1); |
| 105 | ps.compressed[0] = 0; |
| 106 | } |
| 107 | |
| 108 | compressed.write[idx] = ps; |
| 109 | total_compression_size += ps.compressed.size(); |
| 110 | idx++; |
nothing calls this directly
no test coverage detected