From 10096274f9565e9cabf7235e4583df1a782ca6b2 Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Tue, 3 Jan 2012 16:16:40 +0200 Subject: [PATCH] DirectReader._read: avoid potentially expensive string addition Now it behaves same as PipeReader._read() --- rarfile.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/rarfile.py b/rarfile.py index ef9e68b..9552361 100644 --- a/rarfile.py +++ b/rarfile.py @@ -1469,7 +1469,7 @@ class DirectReader(RarExtFile): def _read(self, cnt): """Read from potentially multi-volume archive.""" - buf = EMPTY + buf = [] while cnt > 0: # next vol needed? if self.cur_avail == 0: @@ -1487,12 +1487,11 @@ class DirectReader(RarExtFile): # got some data cnt -= len(data) self.cur_avail -= len(data) - if buf: - buf += data - else: - buf = data + buf.append(data) - return buf + if len(buf) == 1: + return buf[0] + return EMPTY.join(buf) def _open_next(self): """Proceed to next volume.""" -- 2.11.4.GIT