Skip to content

Commit

Permalink
Merge pull request #1487 from charles-cooper/array_copy_optimization
Browse files Browse the repository at this point in the history
Array copy optimization
  • Loading branch information
jacqueswww authored Jun 25, 2019
2 parents ec8e96e + c8cea1b commit b7f9750
Showing 1 changed file with 9 additions and 2 deletions.
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

0 comments on commit b7f9750

Please sign in to comment.