[dpkg] 168/192: Dpkg::Control::HashCore: Optimize first character matching in parse()

Ximin Luo infinity0 at debian.org
Tue Oct 17 11:04:14 UTC 2017


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch pu/reproducible_builds
in repository dpkg.

commit a76b755572bfd7b106ef283193d32fba8cbc5dd1
Author: Guillem Jover <guillem at debian.org>
Date:   Thu Sep 28 09:28:24 2017 +0200

    Dpkg::Control::HashCore: Optimize first character matching in parse()
    
    We store the first character in a variable.
---
 debian/changelog                 | 2 ++
 scripts/Dpkg/Control/HashCore.pm | 6 ++++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 78f9d9d..b49af6d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -98,6 +98,8 @@ dpkg (1.19.0) UNRELEASED; urgency=medium
       method, by trimming it just once at the beginning of the iteration.
     - Optimize trailing space trimming on Dpkg::Control::HashCore parse
       method, by requiring that at least one whitespace is present.
+    - Optimize first character matching in Dpkg::Control::HashCore parse
+      method, by storing the first character in a variable.
   * Documentation:
     - Document currently accepted syntax for changelogs in deb-changelog(5).
       Closes: #858579
diff --git a/scripts/Dpkg/Control/HashCore.pm b/scripts/Dpkg/Control/HashCore.pm
index f33c156..a138698 100644
--- a/scripts/Dpkg/Control/HashCore.pm
+++ b/scripts/Dpkg/Control/HashCore.pm
@@ -207,12 +207,14 @@ sub parse {
         s/\s+$//;
 
         next if length == 0 and $paraborder;
-	next if substr($_, 0, 1) eq '#';
+
+        my $lead = substr $_, 0, 1;
+        next if $lead eq '#';
 	$paraborder = 0;
 	if (m/^(\S+?)\s*:\s*(.*)$/) {
 	    $parabody = 1;
 	    my ($name, $value) = ($1, $2);
-	    if (substr($name, 0, 1) eq '-') {
+            if ($lead eq '-') {
 		$self->parse_error($desc, g_('field cannot start with a hyphen'));
 	    }
 	    if (exists $self->{$name}) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list