summaryrefslogtreecommitdiff
path: root/mesonbuild/ast/printer.py
diff options
context:
space:
mode:
authorVolker Weißmann <volker.weissmann@gmx.de>2025-03-02 10:26:36 +0100
committerDylan Baker <dylan@pnwbakers.com>2025-05-29 09:20:27 -0700
commitbcf1c9ff1f7bcf41bc8af111f51f475a6ac9b25b (patch)
tree3aceef5491cd88cb2d7ba55ba022e56799637c9e /mesonbuild/ast/printer.py
parentf9241c438b947d9b0b30f08948d47e493d6b56d7 (diff)
downloadmeson-bcf1c9ff1f7bcf41bc8af111f51f475a6ac9b25b.tar.gz
AstPrinter: Use str.translate instead of str.replace
Diffstat (limited to 'mesonbuild/ast/printer.py')
-rw-r--r--mesonbuild/ast/printer.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/mesonbuild/ast/printer.py b/mesonbuild/ast/printer.py
index 4ce3b3f1e..10a03bf77 100644
--- a/mesonbuild/ast/printer.py
+++ b/mesonbuild/ast/printer.py
@@ -13,6 +13,8 @@ import typing as T
class AstPrinter(AstVisitor):
+ escape_trans: T.Dict[int, str] = str.maketrans({'\\': '\\\\', "'": "\'"})
+
def __init__(self, indent: int = 2, arg_newline_cutoff: int = 5, update_ast_line_nos: bool = False):
self.result = ''
self.indent = indent
@@ -57,7 +59,7 @@ class AstPrinter(AstVisitor):
node.lineno = self.curr_line or node.lineno
def escape(self, val: str) -> str:
- return val.replace('\\', '\\\\').replace("'", "\'")
+ return val.translate(self.escape_trans)
def visit_StringNode(self, node: mparser.StringNode) -> None:
assert isinstance(node.value, str)