MCPcopy Create free account
hub / github.com/MayaPosch/NymphCast / CopyBuffer

Method CopyBuffer

src/server/angelscript/add_on/scriptarray/scriptarray.cpp:1620–1669  ·  view source on GitHub ↗

internal

Source from the content-addressed store, hash-verified

1618
1619// internal
1620void CScriptArray::CopyBuffer(SArrayBuffer *dst, SArrayBuffer *src)
1621{
1622 asIScriptEngine *engine = objType->GetEngine();
1623 if( subTypeId & asTYPEID_OBJHANDLE )
1624 {
1625 // Copy the references and increase the reference counters
1626 if( dst->numElements > 0 && src->numElements > 0 )
1627 {
1628 int count = dst->numElements > src->numElements ? src->numElements : dst->numElements;
1629
1630 void **max = (void**)(dst->data + count * sizeof(void*));
1631 void **d = (void**)dst->data;
1632 void **s = (void**)src->data;
1633
1634 for( ; d < max; d++, s++ )
1635 {
1636 void *tmp = *d;
1637 *d = *s;
1638 if( *d )
1639 engine->AddRefScriptObject(*d, objType->GetSubType());
1640 // Release the old ref after incrementing the new to avoid problem incase it is the same ref
1641 if( tmp )
1642 engine->ReleaseScriptObject(tmp, objType->GetSubType());
1643 }
1644 }
1645 }
1646 else
1647 {
1648 if( dst->numElements > 0 && src->numElements > 0 )
1649 {
1650 int count = dst->numElements > src->numElements ? src->numElements : dst->numElements;
1651 if( subTypeId & asTYPEID_MASK_OBJECT )
1652 {
1653 // Call the assignment operator on all of the objects
1654 void **max = (void**)(dst->data + count * sizeof(void*));
1655 void **d = (void**)dst->data;
1656 void **s = (void**)src->data;
1657
1658 asITypeInfo *subType = objType->GetSubType();
1659 for( ; d < max; d++, s++ )
1660 engine->AssignScriptObject(*d, *s, subType);
1661 }
1662 else
1663 {
1664 // Primitives are copied byte for byte
1665 memcpy(dst->data, src->data, count*elementSize);
1666 }
1667 }
1668 }
1669}
1670
1671// internal
1672// Precache some info

Callers

nothing calls this directly

Calls 5

AddRefScriptObjectMethod · 0.80
ReleaseScriptObjectMethod · 0.80
AssignScriptObjectMethod · 0.80
GetEngineMethod · 0.45
GetSubTypeMethod · 0.45

Tested by

no test coverage detected