about summary refs log tree commit diff
path: root/src/libextra
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-07-16 14:37:34 -0700
committerbors <bors@rust-lang.org>2013-07-16 14:37:34 -0700
commit53e934c2ab773eaf61da331893d176aa3e62230b (patch)
treee10d9c36f5f1eed33171e2a75381769076fa4857 /src/libextra
parent9db190305f7562f15b5282fed508aef81cfc9689 (diff)
parent3896d46c0a6b99ef166bdc29220ef6c85ad8bc8d (diff)
downloadrust-53e934c2ab773eaf61da331893d176aa3e62230b.tar.gz
rust-53e934c2ab773eaf61da331893d176aa3e62230b.zip
auto merge of #7684 : pnkfelix/rust/fsk-invert-range-rev-halfclosedness-issue5270-2ndpr, r=cmr
Changes int/uint range_rev to iterate over range `(hi,lo]` instead of `[hi,lo)`.

Fix #5270.

Also:
* Adds unit tests for int/uint range functions
* Updates the uses of `range_rev` to account for the new semantics.  (Note that pretty much all of the updates there were strict improvements to the code in question; yay!)
* Exposes new function, `range_step_inclusive`, which does the range `[hi,lo]`, (at least when `hi-lo` is a multiple of the `step` parameter).
* Special-cases when `|step| == 1` removing unnecessary bounds-check.  (I did not check whether LLVM was already performing this optimization; I figure it would be a net win to not leave that analysis to the compiler.  If reviewer objects, I can easily remove that from the refactored code.)

(This pull request is a rebased version of PR #7524, which went stale due to recent unrelated changes to num libraries.)

Diffstat (limited to 'src/libextra')
-rw-r--r--src/libextra/smallintmap.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libextra/smallintmap.rs b/src/libextra/smallintmap.rs
index 27e9f8cd60f..200e8242094 100644
--- a/src/libextra/smallintmap.rs
+++ b/src/libextra/smallintmap.rs
@@ -161,8 +161,8 @@ impl<V> SmallIntMap<V> {
     /// Visit all key-value pairs in reverse order
     pub fn each_reverse<'a>(&'a self, it: &fn(uint, &'a V) -> bool) -> bool {
         for uint::range_rev(self.v.len(), 0) |i| {
-            match self.v[i - 1] {
-              Some(ref elt) => if !it(i - 1, elt) { return false; },
+            match self.v[i] {
+              Some(ref elt) => if !it(i, elt) { return false; },
               None => ()
             }
         }