MCPcopy Create free account
hub / github.com/WheretIB/nullc / VectorPushBack

Function VectorPushBack

NULLC/includes/vector.cpp:41–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39 }
40
41 void VectorPushBack(NULLCRef val, vector* vec)
42 {
43 // Check that we received type that is equal to array element type
44 if(val.typeID != (vec->flags ? nullcGetSubType(vec->elemType) : vec->elemType))
45 {
46 nullcThrowError("vector::push_back received value (%s) that is different from vector type (%s)", nullcGetTypeName(val.typeID), nullcGetTypeName(vec->elemType));
47 return;
48 }
49 // If not enough space
50 if(vec->size == vec->data.len)
51 {
52 // Allocate new
53 unsigned int newSize = 32 > vec->data.len ? 32 : (vec->data.len << 1) + vec->data.len;
54 char *newData = (char*)nullcAllocate(vec->elemSize * newSize);
55 memcpy(newData, vec->data.ptr, vec->elemSize * vec->data.len);
56 vec->data.len = newSize;
57 vec->data.ptr = newData;
58 }
59 memcpy(vec->data.ptr + vec->elemSize * vec->size, vec->flags ? (char*)&val.ptr : val.ptr, vec->elemSize);
60 vec->size++;
61 }
62
63 void VectorPopBack(vector* vec)
64 {

Callers

nothing calls this directly

Calls 4

nullcAllocateFunction · 0.85
nullcGetSubTypeFunction · 0.70
nullcGetTypeNameFunction · 0.70
nullcThrowErrorFunction · 0.50

Tested by

no test coverage detected