From 35bc569bc35ca87503f590e2950b34a33af1395c Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sun, 16 Jul 2023 14:19:06 -0400 Subject: [PATCH] fix lint, add notes --- vyper/codegen/expr.py | 17 ++++++----------- vyper/utils.py | 1 + 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/vyper/codegen/expr.py b/vyper/codegen/expr.py index dfd59c51e85..0acc8fdb6cd 100644 --- a/vyper/codegen/expr.py +++ b/vyper/codegen/expr.py @@ -51,13 +51,7 @@ ) from vyper.semantics.types.bytestrings import _BytestringT from vyper.semantics.types.shortcuts import BYTES32_T, UINT256_T -from vyper.utils import ( - DECIMAL_DIVISOR, - bytes_to_int, - is_checksum_encoded, - string_to_bytes, - vyper_warn, -) +from vyper.utils import DECIMAL_DIVISOR, is_checksum_encoded, string_to_bytes, vyper_warn ENVIRONMENT_VARIABLES = {"block", "msg", "tx", "chain"} @@ -142,15 +136,16 @@ def _make_bytelike(self, btype, bytez, bytez_length): assert isinstance(bytez, bytes) label = _freshname("bytesdata") len_ = len(bytez) + # NOTE: addl opportunities for optimization: + # - intern repeated bytestrings + # - instantiate into memory lazily, pass around bytestring + # literals in IR. ret.append(["data", label, bytez]) ret.append(["codecopy", placeholder + 32, ["symbol", label], len_]) ret.append(["mstore", placeholder, len_]) ret.append(placeholder) return IRnode.from_list( - ret, - typ=btype, - location=MEMORY, - annotation=f"Create {btype}: {bytez}", + ret, typ=btype, location=MEMORY, annotation=f"Create {btype}: {repr(bytez)}" ) # True, False, None constants diff --git a/vyper/utils.py b/vyper/utils.py index 3d9d9cb4168..6aaa677c86c 100644 --- a/vyper/utils.py +++ b/vyper/utils.py @@ -159,6 +159,7 @@ def hex_to_int(inp): # Converts bytes to an integer +# TODO: use int.from_bytes def bytes_to_int(bytez): o = 0 for b in bytez: