automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FYI: speed up Automake::Item::def


From: Alexandre Duret-Lutz
Subject: FYI: speed up Automake::Item::def
Date: Fri, 06 Aug 2004 01:00:57 +0200
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

With this Coreutils is down from 7.48sec to 7.24sec, that's still 5% off.

2004-08-06  Alexandre Duret-Lutz  <address@hidden>

        * lib/Automake/Item.pm (def): Rewrite more concisely, it's faster
        this way.

Index: lib/Automake/Item.pm
===================================================================
RCS file: /cvs/automake/automake/lib/Automake/Item.pm,v
retrieving revision 1.2
diff -u -r1.2 Item.pm
--- lib/Automake/Item.pm        12 Aug 2003 23:32:59 -0000      1.2
+++ lib/Automake/Item.pm        5 Aug 2004 22:55:32 -0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2003  Free Software Foundation, Inc.
+# Copyright (C) 2003, 2004  Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -71,9 +71,12 @@
 
 sub def ($$)
 {
-  my ($self, $cond) = @_;
-  return $self->{'defs'}{$cond} if exists $self->{'defs'}{$cond};
-  return 0;
+  # This method is called very often, so keep it small and fast.  We
+  # don't mind the extra undefined items introduced by lookup failure;
+  # avoiding this with `exists' means doing two hash lookup on
+  # success, and proved worse on benchmark.
+  my $def = $_[0]->{'defs'}{$_[1]};
+  return defined $def && $def;
 }
 
 =item C<$item-E<gt>rdef ($cond)>

-- 
Alexandre Duret-Lutz





reply via email to

[Prev in Thread] Current Thread [Next in Thread]