internal
| 1382 | |
| 1383 | // internal |
| 1384 | void CScriptArray::Sort(asUINT startAt, asUINT count, bool asc) |
| 1385 | { |
| 1386 | // Subtype isn't primitive and doesn't have opCmp |
| 1387 | SArrayCache *cache = reinterpret_cast<SArrayCache*>(objType->GetUserData(ARRAY_CACHE)); |
| 1388 | if( subTypeId & ~asTYPEID_MASK_SEQNBR ) |
| 1389 | { |
| 1390 | if( !cache || cache->cmpFunc == 0 ) |
| 1391 | { |
| 1392 | asIScriptContext *ctx = asGetActiveContext(); |
| 1393 | asITypeInfo* subType = objType->GetEngine()->GetTypeInfoById(subTypeId); |
| 1394 | |
| 1395 | // Throw an exception |
| 1396 | if( ctx ) |
| 1397 | { |
| 1398 | char tmp[512]; |
| 1399 | |
| 1400 | if( cache && cache->cmpFuncReturnCode == asMULTIPLE_FUNCTIONS ) |
| 1401 | #if defined(_MSC_VER) && _MSC_VER >= 1500 && !defined(__S3E__) |
| 1402 | sprintf_s(tmp, 512, "Type '%s' has multiple matching opCmp methods", subType->GetName()); |
| 1403 | #else |
| 1404 | sprintf(tmp, "Type '%s' has multiple matching opCmp methods", subType->GetName()); |
| 1405 | #endif |
| 1406 | else |
| 1407 | #if defined(_MSC_VER) && _MSC_VER >= 1500 && !defined(__S3E__) |
| 1408 | sprintf_s(tmp, 512, "Type '%s' does not have a matching opCmp method", subType->GetName()); |
| 1409 | #else |
| 1410 | sprintf(tmp, "Type '%s' does not have a matching opCmp method", subType->GetName()); |
| 1411 | #endif |
| 1412 | |
| 1413 | ctx->SetException(tmp); |
| 1414 | } |
| 1415 | |
| 1416 | return; |
| 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | // No need to sort |
| 1421 | if( count < 2 ) |
| 1422 | { |
| 1423 | return; |
| 1424 | } |
| 1425 | |
| 1426 | int start = startAt; |
| 1427 | int end = startAt + count; |
| 1428 | |
| 1429 | // Check if we could access invalid item while sorting |
| 1430 | if( start >= (int)buffer->numElements || end > (int)buffer->numElements ) |
| 1431 | { |
| 1432 | asIScriptContext *ctx = asGetActiveContext(); |
| 1433 | |
| 1434 | // Throw an exception |
| 1435 | if( ctx ) |
| 1436 | { |
| 1437 | ctx->SetException("Index out of bounds"); |
| 1438 | } |
| 1439 | |
| 1440 | return; |
| 1441 | } |
no test coverage detected