From 4f91bed904d525666858478a8dc0c01053a6ab14 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 5 Feb 2013 21:59:18 +0100 Subject: [PATCH] Optimize cycling in get_layer_range() --- lib/Slic3r/Print/Object.pm | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index e57620a87..ceeda2646 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -34,11 +34,18 @@ sub get_layer_range { my $self = shift; my ($min_z, $max_z) = @_; + # $min_layer is the uppermost layer having slice_z <= $min_z + # $max_layer is the lowermost layer having slice_z >= $max_z my ($min_layer, $max_layer) = (0, undef); - for my $layer (@{$self->layers}) { - $min_layer = $layer->id if $layer->slice_z <= $min_z; - if ($layer->slice_z >= $max_z) { - $max_layer = $layer->id; + for my $i (0 .. $#{$self->layers}) { + if ($self->layers->[$i]->slice_z >= $min_z) { + $min_layer = $i - 1; + for my $k ($i .. $#{$self->layers}) { + if ($self->layers->[$k]->slice_z >= $max_z) { + $max_layer = $k - 1; + last; + } + } last; } }