1
0
forked from 0ad/0ad

Avoid some redundant HasProperty calls.

This was SVN commit r7578.
This commit is contained in:
Ykkrosh 2010-05-25 18:18:32 +00:00
parent 6fdb947ff0
commit 121d1ead20
2 changed files with 5 additions and 1 deletions

View File

@ -27,6 +27,9 @@ CComponentTypeScript::CComponentTypeScript(ScriptInterface& scriptInterface, jsv
{
debug_assert(instance);
m_ScriptInterface.AddRoot(&m_Instance, "CComponentTypeScript.m_Instance");
// Cache the property detection for efficiency
m_HasCustomSerialize = m_ScriptInterface.HasProperty(m_Instance, "Serialize");
}
CComponentTypeScript::~CComponentTypeScript()
@ -62,7 +65,7 @@ void CComponentTypeScript::Serialize(ISerializer& serialize)
{
// Support a custom "Serialize" function, which returns a new object that will be
// serialized instead of the component itself
if (m_ScriptInterface.HasProperty(m_Instance, "Serialize"))
if (m_HasCustomSerialize)
{
CScriptValRooted val;
if (!m_ScriptInterface.CallFunction(m_Instance, "Serialize", val))

View File

@ -76,6 +76,7 @@ BOOST_PP_REPEAT(SCRIPT_INTERFACE_MAX_ARGS, OVERLOADS, ~)
private:
ScriptInterface& m_ScriptInterface;
jsval m_Instance;
bool m_HasCustomSerialize;
NONCOPYABLE(CComponentTypeScript);
};