]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
perf: use `b"'"[0]` as const value to represent `ord("'")`
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 20 Mar 2022 00:44:07 +0000 (01:44 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 10 May 2022 17:13:26 +0000 (19:13 +0200)
The value is expanded at compile time::

    >>> dis.dis('b"\'"[0]')
      1           0 LOAD_CONST               0 (39)
                  2 RETURN_VALUE

psycopg/psycopg/sql.py

index eb5be8aefc9564d85b95a701be439001d5c3d434..4e0d0d3dece6fe6f1e3cb8fa066dd1bdb0b08df4 100644 (file)
@@ -395,7 +395,7 @@ class Literal(Composable):
         rv = dumper.quote(self._obj)
         # If the result is quoted and the oid not unknown,
         # add an explicit type cast.
-        if rv[-1] == 39 and dumper.oid:
+        if rv[-1] == b"'"[0] and dumper.oid:
             ti = tx.adapters.types.get(dumper.oid)
             if ti:
                 # TODO: ugly encoding just to be decoded by as_string()