Procházet zdrojové kódy

Significantly better memory performance (Thanks @drslump!)

Added __slots__ to RulePtr and Token, resulting in significantly lower memory consumption.

As suggested by @drslump.
tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.6.0
Erez Shinan před 6 roky
rodič
revize
ba0dc789a3
2 změnil soubory, kde provedl 4 přidání a 0 odebrání
  1. +2
    -0
      lark/lexer.py
  2. +2
    -0
      lark/parsers/grammar_analysis.py

+ 2
- 0
lark/lexer.py Zobrazit soubor

@@ -25,6 +25,8 @@ class UnexpectedInput(LexError):
self.considered_rules = considered_rules

class Token(Str):
__slots__ = ('type', 'pos_in_stream', 'value', 'line', 'column', 'end_line', 'end_column')

def __new__(cls, type_, value, pos_in_stream=None, line=None, column=None):
self = super(Token, cls).__new__(cls, value)
self.type = type_


+ 2
- 0
lark/parsers/grammar_analysis.py Zobrazit soubor

@@ -5,6 +5,8 @@ from ..grammar import Rule


class RulePtr(object):
__slots__ = ('rule', 'index')

def __init__(self, rule, index):
assert isinstance(rule, Rule)
assert index <= len(rule.expansion)


Načítá se…
Zrušit
Uložit