MCPcopy Create free account
hub / github.com/ZDoom/Raze / growBuffer

Method growBuffer

libraries/asmjit/asmjit/base/codeholder.cpp:300–344  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

298}
299
300Error CodeHolder::growBuffer(CodeBuffer* cb, size_t n) noexcept {
301 // This is most likely called by `Assembler` so `sync()` shouldn't be needed,
302 // however, if this is called by the user and the currently attached Assembler
303 // did generate some code we could lose that, so sync now and make sure the
304 // section length is updated.
305 if (_cgAsm) _cgAsm->sync();
306
307 // Now the length of the section must be valid.
308 size_t length = cb->getLength();
309 if (ASMJIT_UNLIKELY(n > IntTraits<uintptr_t>::maxValue() - length))
310 return DebugUtils::errored(kErrorNoHeapMemory);
311
312 // We can now check if growing the buffer is really necessary. It's unlikely
313 // that this function is called while there is still room for `n` bytes.
314 size_t capacity = cb->getCapacity();
315 size_t required = cb->getLength() + n;
316 if (ASMJIT_UNLIKELY(required <= capacity)) return kErrorOk;
317
318 if (cb->isFixedSize())
319 return DebugUtils::errored(kErrorCodeTooLarge);
320
321 if (capacity < 8096)
322 capacity = 8096;
323 else
324 capacity += Globals::kAllocOverhead;
325
326 do {
327 size_t old = capacity;
328 if (capacity < Globals::kAllocThreshold)
329 capacity *= 2;
330 else
331 capacity += Globals::kAllocThreshold;
332
333 if (capacity < Globals::kAllocThreshold)
334 capacity *= 2;
335 else
336 capacity += Globals::kAllocThreshold;
337
338 // Overflow.
339 if (ASMJIT_UNLIKELY(old > capacity))
340 return DebugUtils::errored(kErrorNoHeapMemory);
341 } while (capacity - Globals::kAllocOverhead < required);
342
343 return CodeHolder_reserveInternal(this, cb, capacity - Globals::kAllocOverhead);
344}
345
346Error CodeHolder::reserveBuffer(CodeBuffer* cb, size_t n) noexcept {
347 size_t capacity = cb->getCapacity();

Callers 5

embedMethod · 0.80
embedLabelMethod · 0.80
embedConstPoolMethod · 0.80
_emitMethod · 0.80
alignMethod · 0.80

Calls 6

erroredFunction · 0.85
isFixedSizeMethod · 0.80
syncMethod · 0.45
getLengthMethod · 0.45
getCapacityMethod · 0.45

Tested by

no test coverage detected