Skip to content

Commit ca24813

Browse files
committed
remove unnecessary regex usage
1 parent ca62580 commit ca24813

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/etc/lldb_providers.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from __future__ import annotations
2-
import re
32
import sys
43
from typing import List, TYPE_CHECKING
54

@@ -417,8 +416,12 @@ def _getVariantName(variant) -> str:
417416
we can extract `TheVariantName` from it for display purpose.
418417
"""
419418
s = variant.GetType().GetName()
420-
match = re.search(r"::([^:]+)\$Variant$", s)
421-
return match.group(1) if match else ""
419+
if not s.endswith("$Variant"):
420+
return ""
421+
422+
# trim off path and "$Variant"
423+
# len("$Variant") == 8
424+
return s.rsplit("::", 1)[1][:-8]
422425

423426

424427
class ClangEncodedEnumProvider:

src/etc/rust_types.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ class RustType(Enum):
5858
STD_PATHBUF_REGEX = re.compile(r"^(std::([a-z_]+::)+)PathBuf$")
5959
STD_PATH_REGEX = re.compile(r"^&(mut )?(std::([a-z_]+::)+)Path$")
6060

61-
TUPLE_ITEM_REGEX = re.compile(r"__\d+$")
62-
6361
ENCODED_ENUM_PREFIX = "RUST$ENCODED$ENUM$"
6462
ENUM_DISR_FIELD_NAME = "<<variant>>"
6563
ENUM_LLDB_ENCODED_VARIANTS = "$variants$"
@@ -88,7 +86,12 @@ class RustType(Enum):
8886

8987

9088
def is_tuple_fields(fields: List) -> bool:
91-
return all(TUPLE_ITEM_REGEX.match(str(field.name)) for field in fields)
89+
for f in fields:
90+
name = str(f.name)
91+
if not name.startswith("__") or not name[2:].isdigit():
92+
return False
93+
94+
return True
9295

9396

9497
def classify_struct(name: str, fields: List) -> RustType:

0 commit comments

Comments
 (0)