GDScript: Optimize non-constant for-range

This commit is contained in:
Danil Alexeev 2025-05-02 18:43:08 +03:00
parent 3b963ab8b6
commit a13fbc6e3e
No known key found for this signature in database
GPG key ID: 5A52F75A8679EC57
10 changed files with 267 additions and 119 deletions

View file

@ -553,7 +553,7 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
case OPCODE_CONSTRUCT_ARRAY: {
int instr_var_args = _code_ptr[++ip];
int argc = _code_ptr[ip + 1 + instr_var_args];
text += " make_array ";
text += "make_array ";
text += DADDR(1 + argc);
text += " = [";
@ -585,7 +585,7 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
type_name = Variant::get_type_name(builtin_type);
}
text += " make_typed_array (";
text += "make_typed_array (";
text += type_name;
text += ") ";
@ -1181,9 +1181,25 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
incr += 5;
} break;
DISASSEMBLE_ITERATE_TYPES(DISASSEMBLE_ITERATE_BEGIN);
case OPCODE_ITERATE_BEGIN_RANGE: {
text += "for-init ";
text += DADDR(5);
text += " in range from ";
text += DADDR(2);
text += " to ";
text += DADDR(3);
text += " step ";
text += DADDR(4);
text += " counter ";
text += DADDR(1);
text += " end ";
text += itos(_code_ptr[ip + 6]);
incr += 7;
} break;
case OPCODE_ITERATE: {
text += "for-loop ";
text += DADDR(2);
text += DADDR(3);
text += " in ";
text += DADDR(2);
text += " counter ";
@ -1194,6 +1210,20 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
incr += 5;
} break;
DISASSEMBLE_ITERATE_TYPES(DISASSEMBLE_ITERATE);
case OPCODE_ITERATE_RANGE: {
text += "for-loop ";
text += DADDR(4);
text += " in range to ";
text += DADDR(2);
text += " step ";
text += DADDR(3);
text += " counter ";
text += DADDR(1);
text += " end ";
text += itos(_code_ptr[ip + 5]);
incr += 6;
} break;
case OPCODE_STORE_GLOBAL: {
text += "store global ";
text += DADDR(1);