Optimize member access with self
Let the compiler take the fast path when a member is superfluously accessed with `self.`.
This commit is contained in:
parent
c931ed976b
commit
d306b9bea5
|
@ -550,17 +550,25 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
|
||||||
|
|
||||||
int index;
|
int index;
|
||||||
if (named) {
|
if (named) {
|
||||||
#ifdef DEBUG_ENABLED
|
|
||||||
if (on->arguments[0]->type==GDParser::Node::TYPE_SELF && codegen.script && codegen.function_node && !codegen.function_node->_static) {
|
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) {
|
if (MI && MI->get().getter==codegen.function_node->name) {
|
||||||
String n = static_cast<GDParser::IdentifierNode*>(on->arguments[1])->name;
|
String n = static_cast<GDParser::IdentifierNode*>(on->arguments[1])->name;
|
||||||
_set_error("Must use '"+n+"' instead of 'self."+n+"' in getter.",on);
|
_set_error("Must use '"+n+"' instead of 'self."+n+"' in getter.",on);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#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);
|
index=codegen.get_name_map_pos(static_cast<GDParser::IdentifierNode*>(on->arguments[1])->name);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue