深拷贝函数重构优化性能

This commit is contained in:
Lenheart 2024-12-15 20:15:48 +08:00
parent 230ddba3f6
commit d8faa49866
1 changed files with 14 additions and 3 deletions

View File

@ -24,10 +24,21 @@ function print(Object) {
/* /*
* @函数作用: 深拷贝Table * @函数作用: 深拷贝Table
*/ */
// function sq_DeepCopy(original) {
// local Ret = Json.Encode(original);
// Ret = Json.Decode(Ret);
// return Ret;
// }
function sq_DeepCopy(original) { function sq_DeepCopy(original) {
local Ret = Json.Encode(original); local RetTable = clone(original);
Ret = Json.Decode(Ret); foreach(Key, Value in original) {
return Ret; if (typeof Value == "table") {
RetTable[Key] = sq_DeepCopy(Value);
} else if (typeof Value == "array") {
RetTable[Key] = sq_DeepCopy(Value);
}
}
return RetTable;
} }
/* /*