Author: Robie Basak <robie.basak@canonical.com>
Origin: upstream, http://bazaar.launchpad.net/~simplestreams-dev/simplestreams/trunk/revision/430
Bug: https://launchpad.net/bugs/1580534
Bug-Ubuntu: https://launchpad.net/bugs/1580534
Last-Update: 2016-05-12
Subject: Optimise read_signed

Use join instead of iteratively "appending" to a string. In my use case,
this reduces signature check time from over 400 seconds to almost a
tenth of a second.

--- a/simplestreams/util.py	2016-01-25 18:03:00 +0000
+++ b/simplestreams/util.py	2016-05-11 10:38:34 +0000
@@ -288,7 +288,7 @@
                           (' '.join(cmd), e.output[0], e.output[1]))
                 raise e
 
-        ret = {'body': '', 'signature': '', 'garbage': ''}
+        ret = {'body': [], 'signature': [], 'garbage': []}
         lines = content.splitlines()
         i = 0
         for i in range(0, len(lines)):
@@ -308,11 +308,12 @@
 
             # dash-escaped content in body
             if lines[i].startswith("- ") and mode == "body":
-                ret[mode] += lines[i][2:] + "\n"
+                ret[mode].append(lines[i][2:])
             else:
-                ret[mode] += lines[i] + "\n"
+                ret[mode].append(lines[i])
 
-        return ret['body']
+        ret['body'].append('')  # need empty line at end
+        return "\n".join(ret['body'])
     else:
         raise SignatureMissingException("No signature found!")
 

