From nobody Tue May 13 19:28:05 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=famz@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by mx.zohomail.com with SMTPS id 1519700456572138.29273037162284; Mon, 26 Feb 2018 19:00:56 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2A12440201A2 for ; Tue, 27 Feb 2018 03:00:55 +0000 (UTC) Received: from localhost (ovpn-12-53.pek2.redhat.com [10.72.12.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 80E432024CA2 for ; Tue, 27 Feb 2018 03:00:54 +0000 (UTC) Received: by 10.103.98.66 with SMTP id w63csp3595257vsb; Mon, 26 Feb 2018 03:27:26 -0800 (PST) Received: from mx1.redhat.com (mx3-rdu2.redhat.com. [66.187.233.73]) by mx.google.com with ESMTPS id a6si3214545qte.291.2018.02.26.03.27.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 03:27:26 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0C05D4036114 for ; Mon, 26 Feb 2018 11:27:26 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 07C9B2026E04; Mon, 26 Feb 2018 11:27:26 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-126.ams2.redhat.com [10.36.117.126]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67D8E2026DFD; Mon, 26 Feb 2018 11:27:25 +0000 (UTC) Resent-From: Fam Zheng Resent-Date: Tue, 27 Feb 2018 11:00:53 +0800 Resent-Message-ID: <20180227030053.GM21035@lemon.usersys.redhat.com> Resent-To: importer@patchew.org X-Google-Smtp-Source: AG47ELuM0Fup5CUE4YRF+V5Fc/U8IicEaJ9Z8WaGuDzhxBGn2+3u6Rm2mc6sYB5fO5Uj8234Z+S0 X-Received: by 10.200.54.39 with SMTP id m36mr17469140qtb.304.1519644446303; Mon, 26 Feb 2018 03:27:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519644446; cv=none; d=google.com; s=arc-20160816; b=SXWz/hkxTSitg+hlsVP0VsWsK654f2gH3IyZ8xRoQ0u3Z14W+DC63nSkHGhGtCcz6p dT//iaZsnYkTVAuch77aicGux7pevP4TmS+m7/hG+xK+eeOCZz4Ke2rwAwdIbOaNKrGd LeZhnCQBMr3m5P8coijzsA4gtKj2U1qQpXTJZpw7H0V5TzwARmrVMYo13MBDcKbLUZVI FWZJ872MyS7obUmmxStAaankPvYWsQZ0W0IHFUa/apo+FL6uEQVRNV7BolptYwZq2fn2 xcGKSyg25eF3QR8nhkAUjldNk99SQoERmAeoWa8RnyM9PjD83ZZLujPZs3cwsVrHPjKR qe+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :delivered-to:arc-authentication-results; bh=mrtiRiDLqCmojBp+Unj6SEaqz2AKrExWX2tw28WhU08=; b=lngGBIrS4cNGlp+lGk42ONFkz6G10DzpcY4hzdz982TfjXBSTaL6kKAz26ZG+lGE0R eS+/zU4imjsQm/1pxucB4OPZxP7Pt5mc+QAkqHDOAKGw0oaHlarUEwMG3VTpWWn+42uC ++2Pz4FbapN4+8SFnZOBcjbPUyzBw8tfczmxUtYQpYM0zZiAtL01UuWBVYCUO4QTX/rf 1IYwCwAKNdxwJXUyuI1puk8WKcuQnCmNVFB/UoWUl0os73+l5XXuHkJQowy8OWiqzThu 389Z6XRhFcbghkngRSOmMMHQiVCMKrH89aqtLtntr6C479YJe0AZ7hRJM/zLRgwitHN+ fXvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain gapps.redhat.com configured 66.187.233.73 as internal address) smtp.mailfrom=pbonzini@redhat.com Received-SPF: pass (zoho.com: domain of redhat.com designates 66.187.233.73 as permitted sender) client-ip=66.187.233.73; envelope-from=famz@redhat.com; helo=mx1.redhat.com; Received-SPF: pass (google.com: domain gapps.redhat.com configured 66.187.233.73 as internal address) Authentication-Results: mx.google.com; spf=pass (google.com: domain gapps.redhat.com configured 66.187.233.73 as internal address) smtp.mailfrom=pbonzini@redhat.com From: Paolo Bonzini To: patchew-devel@freelists.org Cc: famz@redhat.com Subject: [PATCH 3/9] ansi2html: optimize lines without any control characters Date: Mon, 26 Feb 2018 12:27:16 +0100 Message-Id: <20180226112722.19488-4-pbonzini@redhat.com> In-Reply-To: <20180226112722.19488-1-pbonzini@redhat.com> References: <20180226112722.19488-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 26 Feb 2018 11:27:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 26 Feb 2018 11:27:26 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' X-TUID: hR+c4fPlQbAE X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 27 Feb 2018 03:00:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 27 Feb 2018 03:00:55 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Store the initial part of the line, up to the first control characteer, in a string. If it is followed immediately by \n, \r\n or \f, it can be printed without going through the cursor tracking logic. Signed-off-by: Paolo Bonzini --- patchew/logviewer.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/patchew/logviewer.py b/patchew/logviewer.py index 1e3495b..4523d1c 100644 --- a/patchew/logviewer.py +++ b/patchew/logviewer.py @@ -44,6 +44,8 @@ class ANSI2HTMLConverter(object): def _reset(self): self.line =3D [] self.pos =3D 0 + self.lazy_contents =3D '' + self.lazy_accumulate =3D True =20 # self.line holds the characters for the current line. # Writing can overwrite some characters if self.pos is @@ -51,6 +53,8 @@ class ANSI2HTMLConverter(object): # Moving the cursor right can add spaces to the end. =20 def _write(self, chars): + assert not self.lazy_accumulate or self.lazy_contents =3D=3D '' + self.lazy_accumulate =3D False cur_len =3D len(self.line) if self.pos < cur_len: last =3D min(cur_len - self.pos, len(chars)) @@ -65,6 +69,8 @@ class ANSI2HTMLConverter(object): def _set_pos(self, pos): self.pos =3D pos if self.pos > len(self.line): + assert not self.lazy_accumulate or self.lazy_contents =3D=3D '' + self.lazy_accumulate =3D False num =3D self.pos - len(self.line) self.line +=3D [' '] * num =20 @@ -77,6 +83,14 @@ class ANSI2HTMLConverter(object): yield self.RE_ENTITIES.sub(lambda x: self.ENTITIES[x.group(0)], te= xt) =20 def _write_line(self, suffix): + # If the line consists of a single string of text without no escap= es + # or control chararcters, convert() special cases it + if self.lazy_contents !=3D '': + yield from self._write_span(self.lazy_contents) + yield suffix + self._reset() + return + text =3D "".join(self.line) yield from self._write_span(text) yield suffix @@ -86,14 +100,27 @@ class ANSI2HTMLConverter(object): yield from self._write_prefix() for m in self.RE.finditer(input): if m.group(1): - self._write(m.group(1)) + if self.lazy_accumulate: + self.lazy_contents +=3D m.group(1) + else: + self._write(m.group(1)) else: seq =3D m.group(2) + # _write_line can deal with lazy storage. Everything else + # must be flushed to self.line with _write. if seq =3D=3D '\n': yield from self._write_line('\n') + continue elif seq =3D=3D '\f': yield from self._write_line('\n
') - elif seq =3D=3D '\b': + continue + + if self.lazy_contents !=3D '': + content =3D self.lazy_contents + self.lazy_contents =3D '' + self._write(content) + + if seq =3D=3D '\b': if self.pos > 0: self.pos -=3D 1 elif seq =3D=3D '\t': --=20 2.14.3