MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / impl_allocateString

Method impl_allocateString

src/simulate/heap.cpp:272–291  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

270 }
271
272 char * ConstStringAllocator::impl_allocateString ( const char * text, uint64_t length ) {
273 if ( length ) {
274 // ConstStringAllocator only stores interned strings; the StrHashEntry
275 // length field caps at uint32. Const strings >4GB are pathological.
276 DAS_ASSERTF(length <= UINT32_MAX, "ConstStringAllocator caps at 4GB string length, got %llu", (unsigned long long)length);
277 if ( text ) {
278 auto it = internMap.find(StrHashEntry(text,uint32_t(length)));
279 if ( it != internMap.end() ) {
280 return (char *) it->ptr;
281 }
282 }
283 if ( auto str = (char *)allocate(length + 1) ) {
284 if ( text ) memcpy(str, text, length);
285 str[length] = 0;
286 internMap.insert(StrHashEntry(str,uint32_t(length)));
287 return str;
288 }
289 }
290 return nullptr;
291 }
292
293 char * StringHeapAllocator::impl_allocateString ( Context * context, const char * text, uint64_t length, const LineInfo * at ) {
294 if ( length ) {

Callers 3

bakeConstStringKeyFunction · 0.45
visitMethod · 0.45
internMethod · 0.45

Calls 8

StrHashEntryClass · 0.85
allocateFunction · 0.85
impl_allocateFunction · 0.85
os_debug_breakFunction · 0.85
throw_out_of_memoryMethod · 0.80
findMethod · 0.45
endMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected