View Single Post
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 09-05-2015 , 17:32   Re: [CS:GO] Optimizing function
Reply With Quote #3

PHP Code:
public Native_GetBestRound(Handle:pluginnumParams)
{
    new 
client GetNativeCell(1);
    new 
style GetNativeCell(2);
    new 
track GetNativeCell(3);
    
    new 
String:auth[32];
    if (!
GetClientAuthString(clientauthsizeof(auth))) {
        return 
false;
    }
    
    new 
size GetArraySize(g_hCache[style][track]);
    for (new 
0sizei++)
    {
        new 
nCache[RecordCache];
        
GetArrayArray(g_hCache[style][track], inCache[0]);
        
        if (
StrEqual(nCache[Auth], auth))
        {
            
SetNativeCellRef(4nCache[Time]);
            
SetNativeCellRef(5nCache[Jumps]);
            return 
true;
        }
    }
    
    return 
false;

PHP Code:
public Native_GetStyleRank(Handle:pluginnumParams)
{
    new 
client GetNativeCell(1);
    new 
track GetNativeCell(2);
    new 
style GetNativeCell(3);
    
    new 
String:auth[32];
    if (!
GetClientAuthString(clientauthsizeof(auth))) {
        return 
0;
    }
    
    new 
size GetArraySize(g_hCache[style][track]);
    for (new 
0sizei++)
    {
        new 
nCache[RecordCache];
        
GetArrayArray(g_hCache[style][track], inCache[0]);
        
        if (
StrEqual(nCache[Auth], auth)) {
            return 
i+1;
        }
    }
    
    return 
0;

Is the best you're going to get without modifications outside of those functions, and probably isn't going to save you much at all. The GetArrayArray is indeed going to be expensive (depending on the size of the array) as it has to copy the contents. The best route forwards for these calls would be to have an additional cache in a StringMap keyed on the steamid (I'm going to guess that the current one cannot be easily converted as it is primarily used as an ordered list).
__________________
asherkin is offline