[librsvg/rustification] marker.rs: Iterate on vector slices, instead of ranges, so we can omit bounds checking



commit 77a40fe6c8186802ea3c31813aee4696daf8bdd4
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Nov 9 18:44:50 2016 -0600

    marker.rs: Iterate on vector slices, instead of ranges, so we can omit bounds checking
    
    Several people suggested that I should
    
      for segment in &segments[start .. end] { ... }
    
    instead of
    
      for j in (start .. end) { ... segments[j] }
    
    This way the slice [start .. end] can eliminate bounds checks.
    
    The idiom for reverse iteration here is
    
      for segment in (&segments[0 .. end + 1]).iter ().rev() { ... }
    
    Get a slice, turn it into an iterator, reverse the iterator.

 rust/src/marker.rs |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
---
diff --git a/rust/src/marker.rs b/rust/src/marker.rs
index f9e6673..186ebe9 100644
--- a/rust/src/marker.rs
+++ b/rust/src/marker.rs
@@ -242,14 +242,14 @@ fn get_segment_directionalities (segment: &Segment) -> Option <(f64, f64, f64, f
 fn find_incoming_directionality_backwards (segments: &Vec<Segment>, start_index: usize) -> (bool, f64, f64) {
     /* "go backwards ... within the current subpath until ... segment which has directionality at its end 
point" */
 
-    for j in (0 .. start_index + 1).rev () {
-        match segments[j] {
+    for segment in (&segments[0 .. start_index + 1]).iter ().rev () {
+        match *segment {
             Segment::Degenerate { .. } => {
                 return (false, 0.0, 0.0); /* reached the beginning of the subpath as we ran into a 
standalone point */
             },
 
             Segment::LineOrCurve { .. } => {
-                match get_segment_directionalities (&segments[j]) {
+                match get_segment_directionalities (segment) {
                     Some ((_, _, v2x, v2y)) => { return (true, v2x, v2y); }
                     None => { continue; }
                 }
@@ -263,14 +263,14 @@ fn find_incoming_directionality_backwards (segments: &Vec<Segment>, start_index:
 fn find_outgoing_directionality_forwards (segments: &Vec<Segment>, start_index: usize) -> (bool, f64, f64) {
     /* "go forwards ... within the current subpath until ... segment which has directionality at its start 
point" */
 
-    for j in start_index .. segments.len () {
-        match segments[j] {
+    for segment in &segments[start_index .. segments.len ()] {
+        match *segment {
             Segment::Degenerate { .. } => {
                 return (false, 0.0, 0.0);  /* reached the end of a subpath as we ran into a standalone point 
*/
             },
 
             Segment::LineOrCurve { .. } => {
-                match get_segment_directionalities (&segments[j]) {
+                match get_segment_directionalities (segment) {
                     Some ((v1x, v1y, _, _)) => { return (true, v1x, v1y); }
                     None => { continue; }
                 }


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