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

Method ReadByteCode

src/server/angelscript/angelscript/source/as_restore.cpp:2419–2661  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2417}
2418
2419void asCReader::ReadByteCode(asCScriptFunction *func)
2420{
2421 asASSERT( func->scriptData );
2422
2423 // Read number of instructions
2424 asUINT total, numInstructions;
2425 total = numInstructions = ReadEncodedUInt();
2426
2427 // Reserve some space for the instructions
2428 func->scriptData->byteCode.AllocateNoConstruct(numInstructions, false);
2429
2430 asUINT pos = 0;
2431 while( numInstructions )
2432 {
2433 asBYTE b;
2434 ReadData(&b, 1);
2435
2436 // Allocate the space for the instruction
2437 asUINT len = asBCTypeSize[asBCInfo[b].type];
2438 asUINT newSize = asUINT(func->scriptData->byteCode.GetLength()) + len;
2439 if( func->scriptData->byteCode.GetCapacity() < newSize )
2440 {
2441 // Determine the average size of the loaded instructions and re-estimate the final size
2442 asUINT size = asUINT(float(newSize) / (total - numInstructions) * total) + 1;
2443 func->scriptData->byteCode.AllocateNoConstruct(size, true);
2444 }
2445 if( !func->scriptData->byteCode.SetLengthNoConstruct(newSize) )
2446 {
2447 // Out of memory
2448 error = true;
2449 return;
2450 }
2451
2452 asDWORD *bc = func->scriptData->byteCode.AddressOf() + pos;
2453 pos += len;
2454
2455 switch( asBCInfo[b].type )
2456 {
2457 case asBCTYPE_NO_ARG:
2458 {
2459 *(asBYTE*)(bc) = b;
2460 bc++;
2461 }
2462 break;
2463 case asBCTYPE_W_ARG:
2464 case asBCTYPE_wW_ARG:
2465 case asBCTYPE_rW_ARG:
2466 {
2467 *(asBYTE*)(bc) = b;
2468
2469 // Read the argument
2470 asWORD w = ReadEncodedUInt16();
2471 *(((asWORD*)bc)+1) = w;
2472
2473 bc++;
2474 }
2475 break;
2476 case asBCTYPE_rW_DW_ARG:

Callers

nothing calls this directly

Calls 5

AllocateNoConstructMethod · 0.80
GetCapacityMethod · 0.80
SetLengthNoConstructMethod · 0.80
GetLengthMethod · 0.45
AddressOfMethod · 0.45

Tested by

no test coverage detected