mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
Only freeze once the cached JS values of templates
CParamNodes can be quite large, thus we usually cache the JS::Value when converting them. The AIInterface makes heavy use of it as detected in #7404. However, the cached values are re-frozen everytime, which is a significant waste of time on a large number of templates.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -69,11 +69,6 @@ template<> void Script::ToJSVal<IComponent*>(const ScriptRequest& rq, JS::Mutab
|
||||
template<> void Script::ToJSVal<CParamNode>(const ScriptRequest& rq, JS::MutableHandleValue ret, CParamNode const& val)
|
||||
{
|
||||
val.ToJSVal(rq, true, ret);
|
||||
|
||||
// Prevent modifications to the object, so that it's safe to share between
|
||||
// components and to reconstruct on deserialization
|
||||
if (ret.isObject())
|
||||
Script::DeepFreezeObject(rq, ret);
|
||||
}
|
||||
|
||||
template<> void Script::ToJSVal<const CParamNode*>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CParamNode* const& val)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "ps/CStrIntern.h"
|
||||
#include "ps/Filesystem.h"
|
||||
#include "ps/XML/Xeromyces.h"
|
||||
#include "scriptinterface/Object.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
@@ -382,7 +383,12 @@ void CParamNode::ToJSVal(const ScriptRequest& rq, bool cacheValue, JS::MutableHa
|
||||
ConstructJSVal(rq, ret);
|
||||
|
||||
if (cacheValue)
|
||||
{
|
||||
if (ret.isObject())
|
||||
Script::DeepFreezeObject(rq, ret);
|
||||
|
||||
m_ScriptVal.reset(new JS::PersistentRootedValue(rq.cx, ret));
|
||||
}
|
||||
}
|
||||
|
||||
void CParamNode::ConstructJSVal(const ScriptRequest& rq, JS::MutableHandleValue ret) const
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2022 Wildfire Games.
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -252,6 +252,8 @@ public:
|
||||
* If @p cacheValue is true, then the same JS::Value will be returned each time
|
||||
* this is called (regardless of whether you passed the same @p cx - be careful
|
||||
* to only use the cache in one context).
|
||||
* Cached object values are frozen, using DeepFreezeObject, so that it's safe to
|
||||
* share between components and to reconstruct on deserialization.
|
||||
* When caching, the lifetime of @p cx must be longer than the lifetime of this node.
|
||||
* The cache will be reset if *this* node is modified (e.g. by LoadXML),
|
||||
* but *not* if any child nodes are modified (so don't do that).
|
||||
|
||||
Reference in New Issue
Block a user