MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / BackupFunctionVars

Method BackupFunctionVars

source/var.cpp:1059–1087  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1057
1058
1059ResultType Var::BackupFunctionVars(UserFunc &aFunc, VarBkp *&aVarBackup, int &aVarBackupCount)
1060// All parameters except the first are output parameters that are set for our caller (though caller
1061// is responsible for having initialized aVarBackup to NULL).
1062// If there is nothing to backup, only the aVarBackupCount is changed (to zero).
1063// Returns OK or FAIL.
1064{
1065 if ( !(aVarBackupCount = aFunc.mVars.mCount) ) // Nothing needs to be backed up.
1066 return OK; // Leave aVarBackup set to NULL as set by the caller.
1067
1068 // NOTES ABOUT MALLOC(): Apparently, the implementation of malloc() is quite good, at least for small blocks
1069 // needed to back up 50 or less variables. It nearly as fast as alloca(), at least when the system
1070 // isn't under load and has the memory to spare without swapping. Therefore, the attempt to use alloca to
1071 // speed up recursive script-functions didn't result in enough of a speed-up (only 1 to 5%) to be worth the
1072 // added complexity.
1073 // Since Var is not a POD struct (it contains private members, a custom constructor, etc.), the VarBkp
1074 // POD struct is used to hold the backup because it's probably better performance than using Var's
1075 // constructor to create each backup array element.
1076 if ( !(aVarBackup = (VarBkp *)malloc(aVarBackupCount * sizeof(VarBkp))) ) // Caller will take care of freeing it.
1077 return FAIL;
1078
1079 int i;
1080 aVarBackupCount = 0; // Init only once prior to both loops. aVarBackupCount is being "overloaded" to track the current item in aVarBackup, BUT ALSO its being updated to an actual count in case some statics are omitted from the array.
1081
1082 // Note that Backup() does not make the variable empty after backing it up because that is something
1083 // that must be done by our caller at a later stage.
1084 for (i = 0; i < aFunc.mVars.mCount; ++i)
1085 aFunc.mVars.mItem[i]->Backup(aVarBackup[aVarBackupCount++]);
1086 return OK;
1087}
1088
1089
1090

Callers

nothing calls this directly

Calls 1

BackupMethod · 0.80

Tested by

no test coverage detected