From 0dab1a0ec0776ffd768baeba9f0f4c4087f9d07d Mon Sep 17 00:00:00 2001 From: Dima Kogan Date: Tue, 11 Aug 2009 11:18:52 -0700 Subject: [PATCH] gnuplot driver more efficient. while,shift -> firstidx,splice Ignore-this: 78741ffed855a5122e14486000af4154 darcs-hash:20090811181852-0cb85-ca6a28ee8151f7c8671c0d69dce8f29ed481fe4f.gz --- driveGnuPlots.pl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/driveGnuPlots.pl b/driveGnuPlots.pl index d9af68a..9baab66 100755 --- a/driveGnuPlots.pl +++ b/driveGnuPlots.pl @@ -3,6 +3,7 @@ use strict; use Getopt::Long; use Time::HiRes qw( usleep ); use IO::Handle; +use List::MoreUtils qw( first_index ); use Data::Dumper; autoflush STDOUT 1; @@ -215,9 +216,11 @@ sub cutOld foreach (@curves) { my $xy = $_->{"data"}; - while(@$xy && $xy->[0][0] < $oldestx) + + if( @$xy ) { - shift @$xy; + my $firstInWindow = first_index {$_->[0] >= $oldestx} @$xy; + splice( @$xy, 0, $firstInWindow ) unless $firstInWindow == -1; } } }