[llvm] [utils][filecheck-lint]: speedup filecheck_lint (PR #94191)
Benjamin Chetioui via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 4 03:38:59 PDT 2024
================
@@ -78,32 +78,41 @@ def levenshtein(s1: str, s2: str) -> int: # pylint: disable=g-doc-args
class FileRange:
- """Stores the coordinates of a span on a single line within a file.
+ """Derives the coordinates of a span on a single line within a file.
Attributes:
- line: the line number
- start_column: the (inclusive) column where the span starts
- end_column: the (inclusive) column where the span ends
+ content: line str
+ start_byte: the (inclusive) byte offset the span starts
+ end_byte: the (inclusive) byte offset the span ends
"""
- line: int
- start_column: int
- end_column: int
+ content: str
+ start_byte: int
+ end_byte: int
def __init__(
self, content: str, start_byte: int, end_byte: int
): # pylint: disable=g-doc-args
- """Derives a span's coordinates based on a string and start/end bytes.
-
+ """
`start_byte` and `end_byte` are assumed to be on the same line.
"""
- content_before_span = content[:start_byte]
- self.line = content_before_span.count("\n") + 1
- self.start_column = start_byte - content_before_span.rfind("\n")
- self.end_column = self.start_column + (end_byte - start_byte - 1)
+ self.content = content
+ self.start_byte = start_byte
+ self.end_byte = end_byte
- def __str__(self) -> str:
- return f"{self.line}:{self.start_column}-{self.end_column}"
+ def as_str(self):
+ """
+ Derives span from line and coordinates
+
+ start_column: the (inclusive) column where the span starts
+ end_column: the (inclusive) column where the span ends
+ """
+ content_before_span = self.content[: self.start_byte]
----------------
bchetioui wrote:
Please remove unnecessary space before `self.start_byte`. (See [PEP8](https://peps.python.org/pep-0008/) documentation about slice notation.)
https://github.com/llvm/llvm-project/pull/94191
More information about the llvm-commits
mailing list