Commit 80776e05 authored by Kirill Smelkov's avatar Kirill Smelkov

xfmt/pyq: speedup a bit again

name       old time/op    new time/op    delta
PyQuote-4     976ns ± 0%     950ns ± 0%  -2.64%  (p=0.008 n=5+5)

name       old alloc/op   new alloc/op   delta
PyQuote-4     0.00B          0.00B         ~     (all equal)

name       old allocs/op  new allocs/op  delta
PyQuote-4      0.00           0.00         ~     (all equal)
parent 6a4d2313
......@@ -21,6 +21,11 @@ import (
// return pyAppendQuoteBytes(buf, b)
// }
// bytesContainsByte is like bytes.ContainsRune but a bit faster
func bytesContainsByte(s []byte, c byte) bool {
return bytes.IndexByte(s, c) >= 0
}
// AppendQuotePy appends to buf Python quoting of s
func AppendQuotePy(buf []byte, s string) []byte {
return AppendQuotePyBytes(buf, mem.Bytes(s))
......@@ -31,7 +36,7 @@ func AppendQuotePyBytes(buf, b []byte) []byte {
// smartquotes: choose ' or " as quoting character
// https://github.com/python/cpython/blob/v2.7.13-116-g1aa1803b3d/Objects/stringobject.c#L947
quote := byte('\'')
if bytes.ContainsRune(b, '\'') && !bytes.ContainsRune(b, '"') {
if bytesContainsByte(b, '\'') && !bytesContainsByte(b, '"') {
quote = '"'
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment