From: Daniele Varrazzo Date: Sun, 20 Mar 2022 00:44:07 +0000 (+0100) Subject: perf: use `b"'"[0]` as const value to represent `ord("'")` X-Git-Tag: 3.1~109^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f873937bdee0d3008286e87a264224f50e6ef84;p=thirdparty%2Fpsycopg.git perf: use `b"'"[0]` as const value to represent `ord("'")` The value is expanded at compile time:: >>> dis.dis('b"\'"[0]') 1 0 LOAD_CONST 0 (39) 2 RETURN_VALUE --- diff --git a/psycopg/psycopg/sql.py b/psycopg/psycopg/sql.py index eb5be8aef..4e0d0d3de 100644 --- a/psycopg/psycopg/sql.py +++ b/psycopg/psycopg/sql.py @@ -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()