From d036673d7b9b4a687f9c37047830e603c125083a Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 11 Jun 2016 00:07:54 +0300 Subject: [PATCH] urllib.urequest: Avoid allocating memory when issuing request. Memory will still be allocated when parsing response, but this already saves 164 bytes of memory traffic (x64). --- urllib.urequest/urllib/urequest.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/urllib.urequest/urllib/urequest.py b/urllib.urequest/urllib/urequest.py index 00acb9ae..659c8f3f 100644 --- a/urllib.urequest/urllib/urequest.py +++ b/urllib.urequest/urllib/urequest.py @@ -27,11 +27,17 @@ def urlopen(url, data=None, method="GET"): if proto == "https:": s = ussl.wrap_socket(s) - req = b"%s /%s HTTP/1.0\r\nHost: %s\r\n" % (method, path, host) - s.write(req) + s.write(method) + s.write(b" /") + s.write(path) + s.write(b" HTTP/1.0\r\nHost: ") + s.write(host) + s.write(b"\r\n") if data: - req = b"Content-Length: %d\r\n" % len(data) + s.write(b"Content-Length: ") + s.write(str(len(data))) + s.write(b"\r\n") s.write(b"\r\n") if data: s.write(data)