Skip to content

Commit

Permalink
[refactor, performance] Remove unused 'spids' field on compound_word.
Browse files Browse the repository at this point in the history
AFTER:

$ _bin/osh_parse.opt -n benchmarks/testdata/configure

dumb_alloc:
        gNumNew = 824496
        gNumDelete = 67267
        gMemPos = 18352488

        gNumMalloc = 83244
        gNumFree = 0
        gMemPos2 = 1113888

$ _bin/osh_parse.opt -n benchmarks/testdata/configure-coreutils

dumb_alloc:
        gNumNew = 2282545
        gNumDelete = 187457
        gMemPos = 55296584

        gNumMalloc = 237032
        gNumFree = 0
	gMemPos2 = 3353424
  • Loading branch information
Andy Chu committed Dec 15, 2019
1 parent 88ab921 commit 398b293
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion frontend/syntax.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ module syntax
| ExprSub(Token left, expr child)
attributes (int* spids)

compound_word = (word_part* parts, int* spids)
compound_word = (word_part* parts)

word =
-- Empty is for the RHS of 'x=', 'declare x=', and the argument in "${x:-}".
-- Semantically, we need it for "${x:-}" (see osh/word_parse.py). Other
Expand Down
6 changes: 3 additions & 3 deletions osh/braces.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def _BraceDetect(w):
# ? We're forcing braces right now but not commas.
if len(stack):
stack[-1].saw_comma = True
stack[-1].alt_part.words.append(compound_word(cur_parts, None))
stack[-1].alt_part.words.append(compound_word(cur_parts))
cur_parts = [] # clear
append = False

Expand Down Expand Up @@ -272,7 +272,7 @@ def _BraceDetect(w):
if not stack[-1].saw_comma: # {foo} is not a real alternative
return None # early return

stack[-1].alt_part.words.append(compound_word(cur_parts, None))
stack[-1].alt_part.words.append(compound_word(cur_parts))

frame = stack.pop()
cur_parts = frame.cur_parts
Expand Down Expand Up @@ -481,7 +481,7 @@ def BraceExpandWords(words):
if case(word_e.BracedTree):
w = cast(word__BracedTree, UP_w)
parts_list = _BraceExpand(w.parts)
tmp = [compound_word(p, None) for p in parts_list]
tmp = [compound_word(p) for p in parts_list]
out.extend(tmp)

elif case(word_e.Compound):
Expand Down
2 changes: 1 addition & 1 deletion osh/cmd_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def _EvalRedirect(self, n):

elif n.tag == redir_e.HereDoc:
# HACK: Wrap it in a word to evaluate.
w = compound_word(n.stdin_parts, None)
w = compound_word(n.stdin_parts)
val = self.word_ev.EvalWordToString(w)
assert val.tag == value_e.Str, val
return redirect.HereDoc(fd, val.s, n.op.span_id)
Expand Down
4 changes: 2 additions & 2 deletions osh/cmd_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def _MakeAssignPair(parse_ctx, preparsed, arena):
if part_offset == n:
val = word.Empty() # type: word_t
else:
val = compound_word(w.parts[part_offset:], None)
val = compound_word(w.parts[part_offset:])
tilde = word_.TildeDetect(val)
if tilde:
val = tilde
Expand Down Expand Up @@ -273,7 +273,7 @@ def _AppendMoreEnv(preparsed_list, more_env):
if part_offset == n:
val = word.Empty() # type: word_t
else:
val = compound_word(w.parts[part_offset:], None)
val = compound_word(w.parts[part_offset:])

pair = syntax_asdl.env_pair(var_name, val, [left_token.span_id])
more_env.append(pair)
Expand Down
10 changes: 5 additions & 5 deletions osh/word_.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def TildeDetect(UP_w):

if len(w.parts) == 1: # can't be zero
tilde_part = word_part.TildeSub(tok0)
return compound_word([tilde_part], None)
return compound_word([tilde_part])

UP_part1 = w.parts[1]
# NOTE: We could inspect the raw tokens.
Expand All @@ -378,7 +378,7 @@ def TildeDetect(UP_w):

parts = [tilde_part_]
parts.extend(w.parts[1:])
return compound_word(parts, None)
return compound_word(parts)

# It could be something like '~foo:bar', which doesn't have a slash.
return None
Expand Down Expand Up @@ -528,8 +528,8 @@ def DetectAssocPair(w):
id_ = _LiteralId(parts[i])
if id_ == Id.Lit_ArrayLhsClose: # ]=
# e.g. if we have [$x$y]=$a$b
key = compound_word(parts[1:i], None) # $x$y
value = compound_word(parts[i+1:], None) # $a$b from
key = compound_word(parts[1:i]) # $x$y
value = compound_word(parts[i+1:]) # $a$b from

# Type-annotated intermediate value for mycpp translation
ret = key, value # type: Optional[Tuple[compound_word, compound_word]]
Expand Down Expand Up @@ -715,7 +715,7 @@ def ErrorWord(fmt, err):
# type: (str, _ErrorWithLocation) -> compound_word
error_str = fmt % err.UserErrorString()
t = Token(Id.Lit_Chars, runtime.NO_SPID, error_str)
return compound_word([t], None)
return compound_word([t])


def Pretty(w):
Expand Down

0 comments on commit 398b293

Please sign in to comment.