summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGreg Price <gnprice@gmail.com>2019-09-10 08:51:04 (GMT)
committerBenjamin Peterson <benjamin@python.org>2019-09-10 08:51:04 (GMT)
commit0711642eec58d00f31031279df799fbddaf6f2c1 (patch)
tree316dc982ee14ff622154f07eb1f34f706f1bf51a /Objects
parent2fc1160a80733f4c5c88796319154b3f59e98e4b (diff)
downloadcpython-0711642eec58d00f31031279df799fbddaf6f2c1.zip
cpython-0711642eec58d00f31031279df799fbddaf6f2c1.tar.gz
cpython-0711642eec58d00f31031279df799fbddaf6f2c1.tar.bz2
Cut tricky `goto` that isn't needed, in _PyBytes_DecodeEscape. (GH-15825)
This is the sort of `goto` that requires the reader to stare hard at the code to unpick what it's doing. On doing so, the answer is... not very much! * It jumps from the bottom of the loop to almost the top; the effect is to bypass the loop condition `s < end` and also the `if`-condition `*s != '\\'`, acting as if both are true. * We've just decremented `s`, after incrementing it in the `switch` condition. So it has the same value as when `s == end` failed. Before that was another increment... and before that we had `s < end`. So `s < end` true, then increment, then `s == end` false... that means `s < end` is still true. * Also this means `s` points to the same character as it did for the `switch` condition. And there was a `case '\\'`, which we didn't hit -- so `*s != '\\'` is also true. * That means this has no effect on the behavior! The most it might do is an optimization -- we get to skip those two checks, because (as just proven above) we know they're true. * But gosh, this is the *invalid escape sequence* path. This does not seem like the kind of code path that calls for extreme optimization tricks. So, take the `goto` and the label out. Perhaps the compiler will notice the exact same facts we showed above, and generate identical code. Or perhaps it won't! That'll be OK. But then, crucially, if some future edit to this loop causes the reasoning above to *stop* holding true... the compiler will adjust this jump accordingly. One of us fallible humans might not.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/bytesobject.c3
1 files changed, 0 insertions, 3 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 6d55330..72f9cd2 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -1142,7 +1142,6 @@ PyObject *_PyBytes_DecodeEscape(const char *s,
end = s + len;
while (s < end) {
if (*s != '\\') {
- non_esc:
if (!(recode_encoding && (*s & 0x80))) {
*p++ = *s++;
}
@@ -1229,8 +1228,6 @@ PyObject *_PyBytes_DecodeEscape(const char *s,
}
*p++ = '\\';
s--;
- goto non_esc; /* an arbitrary number of unescaped
- UTF-8 bytes may follow. */
}
}