summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-07-01 12:25:26 -0300
committerGitHub <noreply@github.com>2016-07-01 12:25:26 -0300
commit48959f0590665e9c958cafc7786a764365f4feb2 (patch)
treef446358a21899793e1f84eeb7e8f508af77a5b94
parentec94dd7eeebb218c51baedb1e63c02e77f8a2c9a (diff)
parentd306b9bea57660676f10229dd65fc885e173f268 (diff)
Merge pull request #5407 from RandomShaper/opt-self-indexing
Optimize member access with self
-rw-r--r--modules/gdscript/gd_compiler.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp
index d9bbe42979..1f76f025d4 100644
--- a/modules/gdscript/gd_compiler.cpp
+++ b/modules/gdscript/gd_compiler.cpp
@@ -550,17 +550,25 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
int index;
if (named) {
-#ifdef DEBUG_ENABLED
if (on->arguments[0]->type==GDParser::Node::TYPE_SELF && codegen.script && codegen.function_node && !codegen.function_node->_static) {
- const Map<StringName,GDScript::MemberInfo>::Element *MI = codegen.script->member_indices.find(static_cast<GDParser::IdentifierNode*>(on->arguments[1])->name);
+ GDParser::IdentifierNode* identifier = static_cast<GDParser::IdentifierNode*>(on->arguments[1]);
+ const Map<StringName,GDScript::MemberInfo>::Element *MI = codegen.script->member_indices.find(identifier->name);
+
+#ifdef DEBUG_ENABLED
if (MI && MI->get().getter==codegen.function_node->name) {
String n = static_cast<GDParser::IdentifierNode*>(on->arguments[1])->name;
_set_error("Must use '"+n+"' instead of 'self."+n+"' in getter.",on);
return -1;
}
- }
#endif
+
+ if (MI && MI->get().getter=="") {
+ // Faster than indexing self (as if no self. had been used)
+ return (MI->get().index)|(GDFunction::ADDR_TYPE_MEMBER<<GDFunction::ADDR_BITS);
+ }
+ }
+
index=codegen.get_name_map_pos(static_cast<GDParser::IdentifierNode*>(on->arguments[1])->name);
} else {