MCPcopy Create free account
hub / github.com/defold/defold / FindEntry

Function FindEntry

engine/resource/src/resource_archive.cpp:214–262  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

212 }
213
214 dmResourceArchive::Result FindEntry(dmResourceArchive::HArchiveIndexContainer archive, const uint8_t* hash, uint32_t hash_len, dmResourceArchive::EntryData** entry)
215 {
216 uint32_t entry_count = dmEndian::ToNetwork(archive->m_ArchiveIndex->m_EntryDataCount);
217 uint32_t entry_offset = dmEndian::ToNetwork(archive->m_ArchiveIndex->m_EntryDataOffset);
218 uint32_t hash_offset = dmEndian::ToNetwork(archive->m_ArchiveIndex->m_HashOffset);
219 uint8_t* hashes = 0;
220 dmResourceArchive::EntryData* entries = 0;
221
222 // If archive is loaded from file use the member arrays for hashes and entries, otherwise read with mem offsets.
223 if (!archive->m_IsMemMapped)
224 {
225 hashes = archive->m_ArchiveFileIndex->m_Hashes;
226 entries = archive->m_ArchiveFileIndex->m_Entries;
227 }
228 else
229 {
230 hashes = (uint8_t*)((uintptr_t)archive->m_ArchiveIndex + hash_offset);
231 entries = (dmResourceArchive::EntryData*)((uintptr_t)archive->m_ArchiveIndex + entry_offset);
232 }
233
234 // Search for hash with binary search (entries are sorted on hash)
235 int first = 0;
236 int last = (int)entry_count-1;
237 while (first <= last)
238 {
239 int mid = first + (last - first) / 2;
240 uint8_t* h = (hashes + dmResourceArchive::MAX_HASH * mid);
241
242 int cmp = memcmp(hash, h, hash_len);
243 if (cmp == 0)
244 {
245 if (entry != 0)
246 {
247 *entry = &entries[mid];
248 }
249 return dmResourceArchive::RESULT_OK;
250 }
251 else if (cmp > 0)
252 {
253 first = mid+1;
254 }
255 else if (cmp < 0)
256 {
257 last = mid-1;
258 }
259 }
260
261 return dmResourceArchive::RESULT_NOT_FOUND;
262 }
263
264 void DebugArchiveIndex(HArchiveIndexContainer archive)
265 {

Callers 4

VerifyResourcesBundledFunction · 0.70
GetDependenciesInternalFunction · 0.70
CreateEntryMapFunction · 0.50
TESTFunction · 0.50

Calls 1

ToNetworkFunction · 0.85

Tested by 1

TESTFunction · 0.40