MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / LoadFromMappedBuffer

Method LoadFromMappedBuffer

src/MarisaDict.cpp:190–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188}
189
190void MarisaDict::LoadFromMappedBuffer() {
191 try {
192 internal->marisa->map(internal->mappedBuffer.data(),
193 internal->mappedBuffer.size());
194 } catch (const std::exception& e) {
195 throw InvalidFormat(std::string("Invalid OpenCC Marisa dictionary: ") +
196 e.what());
197 }
198
199 const size_t trieSize = internal->marisa->io_size();
200 if (trieSize > internal->mappedBuffer.size()) {
201 throw InvalidFormat(
202 "Invalid OpenCC Marisa dictionary (trie exceeds file size)");
203 }
204
205 size_t valuesBytesRead = 0;
206 std::shared_ptr<SerializedValues> serialized_values =
207 SerializedValues::NewFromBuffer(
208 internal->mappedBuffer.data() + trieSize,
209 internal->mappedBuffer.size() - trieSize, &valuesBytesRead);
210 valuesLexicon = serialized_values->GetLexicon();
211 // Validate key count consistency
212 size_t numKeys = internal->marisa->num_keys();
213 if (numKeys != valuesLexicon->Length()) {
214 throw InvalidFormat(
215 "Invalid OpenCC Marisa dictionary (key count mismatch)");
216 }
217 maxLength = 128;
218 lexiconReconstructed.store(false, std::memory_order_release);
219}
220
221
222MarisaDictPtr MarisaDict::NewFromDict(const Dict& thatDict) {

Callers 2

NewFromFileMethod · 0.80
NewFromBufferMethod · 0.80

Calls 8

mapMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
whatMethod · 0.45
io_sizeMethod · 0.45
GetLexiconMethod · 0.45
num_keysMethod · 0.45
LengthMethod · 0.45

Tested by

no test coverage detected