Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array copy optimization #1487

Merged
merged 1 commit into from
Jun 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions vyper/parser/parser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def getpos(node):

# Take a value representing a memory or storage location, and descend down to
# an element or member variable
def add_variable_offset(parent, key, pos):
def add_variable_offset(parent, key, pos, array_bounds_check=True):
typ, location = parent.typ, parent.location
if isinstance(typ, (StructType, TupleType)):
if isinstance(typ, StructType):
Expand Down Expand Up @@ -338,7 +338,9 @@ def add_variable_offset(parent, key, pos):
if not is_base_type(key.typ, ('int128', 'uint256')):
raise TypeMismatchException('Invalid type for array index: %r' % key.typ, pos)

if key.typ.is_literal: # note: BaseType always has is_literal attr
if not array_bounds_check:
sub = k
elif key.typ.is_literal: # note: BaseType always has is_literal attr
# perform the check at compile time and elide the runtime check.
if key.value < 0 or key.value >= typ.count:
raise ArrayIndexException(
Expand Down Expand Up @@ -565,16 +567,19 @@ def make_setter(left, right, location, pos, in_function_call=False):
left_token,
LLLnode.from_list(i, typ='int128'),
pos=pos,
array_bounds_check=False,
), right.args[i], location, pos=pos))
return LLLnode.from_list(['with', '_L', left, ['seq'] + subs], typ=None)
# If the right side is a null
# CC 20190619 probably not needed as of #1106
elif isinstance(right.typ, NullType):
subs = []
for i in range(left.typ.count):
subs.append(make_setter(add_variable_offset(
left_token,
LLLnode.from_list(i, typ='int128'),
pos=pos,
array_bounds_check=False,
), LLLnode.from_list(None, typ=NullType()), location, pos=pos))
return LLLnode.from_list(['with', '_L', left, ['seq'] + subs], typ=None)
# If the right side is a variable
Expand All @@ -586,10 +591,12 @@ def make_setter(left, right, location, pos, in_function_call=False):
left_token,
LLLnode.from_list(i, typ='int128'),
pos=pos,
array_bounds_check=False,
), add_variable_offset(
right_token,
LLLnode.from_list(i, typ='int128'),
pos=pos,
array_bounds_check=False,
), location, pos=pos))
return LLLnode.from_list([
'with', '_L', left, [
Expand Down