Skip to content

Commit 4852565

Browse files
authored
fix: Use counter instead of stack in get_closing_paren_index() (#420)
1 parent 2892c8b commit 4852565

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

addons/mod_loader/internal/mod_hook_preprocessor.gd

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,21 @@ static func get_function_parameters(method_name: String, text: String, is_static
168168

169169

170170
static func get_closing_paren_index(opening_paren_index: int, text: String) -> int:
171-
# Use a stack to match parentheses
172-
var stack := []
171+
# Use a stack counter to match parentheses
172+
var stack := 0
173173
var closing_paren_index := opening_paren_index
174174
while closing_paren_index < text.length():
175175
var char := text[closing_paren_index]
176176
if char == '(':
177-
stack.push_back('(')
177+
stack += 1
178178
elif char == ')':
179-
stack.pop_back()
180-
if stack.size() == 0:
179+
stack -= 1
180+
if stack == 0:
181181
break
182182
closing_paren_index += 1
183183

184184
# If the stack is not empty, that means there's no matching closing parenthesis
185-
if stack.size() != 0:
185+
if stack != 0:
186186
return -1
187187

188188
return closing_paren_index
@@ -222,6 +222,8 @@ static func edit_vanilla_method(
222222

223223
static func fix_method_super(method_name: String, func_def_end: int, text: String, regex_func_body: RegEx, regex_super_call: RegEx, offset := 0) -> String:
224224
var closing_paren_index := get_closing_paren_index(func_def_end, text)
225+
if closing_paren_index == -1:
226+
return text
225227
var func_body_start_index := text.find(":", closing_paren_index) +1
226228

227229
var func_body := regex_func_body.search(text, func_body_start_index)

0 commit comments

Comments
 (0)