[padb-devel] [padb] r210 committed - Improve and document the performance of the rng_add_value() function i...
codesite-noreply at google.com
codesite-noreply at google.com
Tue Sep 8 20:20:07 BST 2009
Revision: 210
Author: apittman
Date: Tue Sep 8 12:19:39 2009
Log: Improve and document the performance of the rng_add_value() function
in the common case,
don't abort if a value is already in the range.
http://code.google.com/p/padb/source/detail?r=210
Modified:
/branches/cleanup/src/padb
=======================================
--- /branches/cleanup/src/padb Tue Sep 8 12:16:20 2009
+++ /branches/cleanup/src/padb Tue Sep 8 12:19:39 2009
@@ -3887,6 +3887,11 @@
return $value;
}
+# Note the performance of this function is much higher when adding
+# values at the top of the range than at the start, persumably it's
+# easier to make an array longer than it is to unshift something onto
+# the start.
+# Quietly return if the value is already in the range.
sub rng_add_value {
my ( $rg, $value ) = @_;
@@ -3896,7 +3901,13 @@
}
# If it's after the last value then just add it.
- if ( $value > $rg->[-1]->{u} + 1 ) {
+ if ( $value > $rg->[-1]->{u} ) {
+
+ if ( $value == $rg->[-1]->{u} + 1 ) {
+ $rg->[-1]->{u}++;
+ return;
+ }
+
push @{$rg}, { l => $value, u => $value };
return;
}
@@ -3928,7 +3939,8 @@
}
return;
} elsif ( $value >= $part->{l} and $value <= $part->{u} ) {
- carp('Failed to add value to range (Value already in range)');
+
+ # Already in range.
return;
}
$idx++;
More information about the padb-devel
mailing list