소스 검색

Use loops for flow control instead of catching exceptions

While optimizing hot spots in a tool I wrote I saw this issue. Changing this to use a for loop granted a minor speed boost to my script.
tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.5.5
Parker 6 년 전
committed by GitHub
부모
커밋
ce26c7cced
No known key found for this signature in database GPG 키 ID: 4AEE18F83AFDEB23
1개의 변경된 파일2개의 추가작업 그리고 7개의 파일을 삭제
  1. +2
    -7
      lark/parsers/lalr_parser.py

+ 2
- 7
lark/parsers/lalr_parser.py 파일 보기

@@ -66,9 +66,7 @@ class _Parser:
value_stack.append(value)

# Main LALR-parser loop
try:
token = next(stream)
i += 1
for i, token in enumerate(stream):
while True:
action, arg = get_action(token.type)
assert arg != self.end_state
@@ -77,12 +75,9 @@ class _Parser:
state_stack.append(arg)
value_stack.append(token)
if set_state: set_state(arg)
token = next(stream)
i += 1
break # next token
else:
reduce(arg)
except StopIteration:
pass

while True:
_action, arg = get_action('$END')


불러오는 중...
취소
저장