about summary refs log tree commit diff
path: root/src/libstd/priority_queue.rs
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2012-12-11 09:47:36 -0500
committerBrian Anderson <banderson@mozilla.com>2012-12-16 19:27:06 -0800
commit8b13bf75306d7b5645531a0eb273b9ce9805e009 (patch)
tree71f9e7b90672d999986e0fa70f6a7d9fde87892d /src/libstd/priority_queue.rs
parent285496bd550817094c31167e7e49378a35560842 (diff)
downloadrust-8b13bf75306d7b5645531a0eb273b9ce9805e009.tar.gz
rust-8b13bf75306d7b5645531a0eb273b9ce9805e009.zip
priority_queue: replace some copies with swaps
Diffstat (limited to 'src/libstd/priority_queue.rs')
-rw-r--r--src/libstd/priority_queue.rs16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/libstd/priority_queue.rs b/src/libstd/priority_queue.rs
index b92f5f57a5f..ab274970ab3 100644
--- a/src/libstd/priority_queue.rs
+++ b/src/libstd/priority_queue.rs
@@ -38,13 +38,9 @@ impl <T: Copy Ord> PriorityQueue<T> {
 
     /// Pop the greatest item from the queue - fails if empty
     fn pop(&mut self) -> T {
-        let last = self.data.pop();
-        if self.is_not_empty() {
-            let ret = self.data[0];
-            self.data[0] = last;
-            self.siftup(0);
-            ret
-        } else { last }
+        let mut item = self.data.pop();
+        if self.is_not_empty() { item <-> self.data[0]; self.siftup(0); }
+        item
     }
 
     /// Pop the greatest item from the queue - None if empty
@@ -70,10 +66,10 @@ impl <T: Copy Ord> PriorityQueue<T> {
 
     /// Optimized version of a pop followed by a push - fails if empty
     fn replace(&mut self, item: T) -> T {
-        let ret = self.data[0];
-        self.data[0] = item;
+        let mut item = item;
+        item <-> self.data[0];
         self.siftup(0);
-        ret
+        item
     }
 
     /// Consume the PriorityQueue and return the underlying vector