Skip to content

Commit

Permalink
Optimization: use str.startswith(tuple), and str.endswith(tuple),…
Browse files Browse the repository at this point in the history
… when revelant (crytic#1186)
  • Loading branch information
BoboTiG authored May 4, 2022
1 parent d5d95fe commit 39f5585
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion slither/core/declarations/solidity_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(self, name: str):

# dev function, will be removed once the code is stable
def _check_name(self, name: str): # pylint: disable=no-self-use
assert name in SOLIDITY_VARIABLES or name.endswith("_slot") or name.endswith("_offset")
assert name in SOLIDITY_VARIABLES or name.endswith(("_slot", "_offset"))

@property
def state_variable(self):
Expand Down
2 changes: 1 addition & 1 deletion slither/detectors/naming_convention/naming_convention.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _detect(self): # pylint: disable=too-many-branches,too-many-statements
"private",
] and self.is_mixed_case_with_underscore(func.name):
continue
if func.name.startswith("echidna_") or func.name.startswith("crytic_"):
if func.name.startswith(("echidna_", "crytic_")):
continue
info = ["Function ", func, " is not in mixedCase\n"]

Expand Down
4 changes: 2 additions & 2 deletions slither/solc_parsing/yul/parse_yul.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,15 +737,15 @@ def _parse_yul_magic_suffixes(name: str, root: YulScope) -> Optional[Expression]
# Currently SlithIR doesnt support raw access to memory
# So things like .offset/.slot will return the variable
# Instaed of the actual offset/slot
if name.endswith("_slot") or name.endswith(".slot"):
if name.endswith(("_slot", ".slot")):
potential_name = name[:-5]
variable_found = _check_for_state_variable_name(root, potential_name)
if variable_found:
return variable_found
var = root.function.get_local_variable_from_name(potential_name)
if var and var.is_storage:
return Identifier(var)
if name.endswith("_offset") or name.endswith(".offset"):
if name.endswith(("_offset", ".offset")):
potential_name = name[:-7]
variable_found = _check_for_state_variable_name(root, potential_name)
if variable_found:
Expand Down
2 changes: 1 addition & 1 deletion slither/utils/integer_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def convert_string_to_int(val: Union[str, int]) -> int:
if isinstance(val, int):
return val
if val.startswith("0x") or val.startswith("0X"):
if val.startswith(("0x", "0X")):
return int(val, 16)

if "e" in val or "E" in val:
Expand Down

0 comments on commit 39f5585

Please sign in to comment.