From d5a79545b68ed3c79758ec5381c7dcd7005bde61 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 22 Mar 2014 11:25:18 +0100 Subject: [PATCH 1/5] Update to current rust: std::vec -> std::slice. --- util.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util.rs b/util.rs index 62e2b89..0b672a7 100644 --- a/util.rs +++ b/util.rs @@ -9,11 +9,11 @@ // Miscellaneous utilities. -use std::vec; +use std::slice; pub fn convert_rgb32_to_rgb24(buffer: ~[u8]) -> ~[u8] { let mut i = 0; - vec::from_fn(buffer.len() * 3 / 4, |j| { + slice::from_fn(buffer.len() * 3 / 4, |j| { match j % 3 { 0 => { buffer[i + 2] From 03aebfccfaeef56544a82d898fe71e8194e238e9 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 22 Mar 2014 11:28:21 +0100 Subject: [PATCH 2/5] Update to current rust: remove explicit borrow() calls. --- layers.rs | 79 ++++++++++++++++++++++++----------------------------- rendergl.rs | 4 +-- 2 files changed, 37 insertions(+), 46 deletions(-) diff --git a/layers.rs b/layers.rs index aed98ea..89d3942 100644 --- a/layers.rs +++ b/layers.rs @@ -30,11 +30,11 @@ impl Layer { pub fn with_common(&self, f: |&mut CommonLayer| -> T) -> T { match *self { ContainerLayerKind(ref container_layer) => { - let mut tmp = container_layer.borrow().common.borrow_mut(); + let mut tmp = container_layer.common.borrow_mut(); f(tmp.get()) }, TextureLayerKind(ref texture_layer) => { - let mut tmp = texture_layer.borrow().common.borrow_mut(); + let mut tmp = texture_layer.common.borrow_mut(); f(tmp.get()) }, } @@ -104,11 +104,8 @@ impl Iterator for ChildIterator { impl ContainerLayer { pub fn children(&self) -> ChildIterator { - ChildIterator { current: { - // NOTE: work around borrowchk - let tmp = self.first_child.borrow(); - tmp.get().clone() - } + ChildIterator { + current: self.first_child.get().clone(), } } @@ -122,26 +119,22 @@ impl ContainerLayer { new_child_common.parent = Some(ContainerLayerKind(pseudo_self.clone())); - // NOTE: work around borrowchk - { - let tmp = pseudo_self.borrow().first_child.borrow(); - match *tmp.get() { - None => {} - Some(ref first_child) => { - first_child.with_common(|first_child_common| { - assert!(first_child_common.prev_sibling.is_none()); - first_child_common.prev_sibling = Some(new_child.clone()); - new_child_common.next_sibling = Some(first_child.clone()); - }); - } + match pseudo_self.first_child.get() { + None => {} + Some(ref first_child) => { + first_child.with_common(|first_child_common| { + assert!(first_child_common.prev_sibling.is_none()); + first_child_common.prev_sibling = Some(new_child.clone()); + new_child_common.next_sibling = Some(first_child.clone()); + }); } } - pseudo_self.borrow().first_child.set(Some(new_child.clone())); + pseudo_self.first_child.set(Some(new_child.clone())); - let should_set = pseudo_self.borrow().last_child.borrow().get().is_none(); + let should_set = pseudo_self.last_child.get().is_none(); if should_set { - pseudo_self.borrow().last_child.set(Some(new_child.clone())); + pseudo_self.last_child.set(Some(new_child.clone())); } }); } @@ -156,28 +149,26 @@ impl ContainerLayer { new_child_common.parent = Some(ContainerLayerKind(pseudo_self.clone())); - // NOTE: work around borrowchk - { - let tmp = pseudo_self.borrow().last_child.borrow(); - match *tmp.get() { - None => {} - Some(ref last_child) => { - last_child.with_common(|last_child_common| { - assert!(last_child_common.next_sibling.is_none()); - last_child_common.next_sibling = Some(new_child.clone()); - new_child_common.prev_sibling = Some(last_child.clone()); - }); - } + + match pseudo_self.last_child.get() { + None => {} + Some(ref last_child) => { + last_child.with_common(|last_child_common| { + assert!(last_child_common.next_sibling.is_none()); + last_child_common.next_sibling = Some(new_child.clone()); + new_child_common.prev_sibling = Some(last_child.clone()); + }); } } - pseudo_self.borrow().last_child.set(Some(new_child.clone())); + pseudo_self.last_child.set(Some(new_child.clone())); - pseudo_self.borrow().first_child.with_mut(|child| - match *child { - Some(_) => {}, - None => *child = Some(new_child.clone()), - }); + pseudo_self.first_child.with_mut(|child| { + match *child { + Some(_) => {}, + None => *child = Some(new_child.clone()), + } + }); }); } @@ -186,15 +177,15 @@ impl ContainerLayer { assert!(child_common.parent.is_some()); match child_common.parent { Some(ContainerLayerKind(ref container)) => { - assert!(container.borrow() as *ContainerLayer == - pseudo_self.borrow() as *ContainerLayer); + assert!(container.deref() as *ContainerLayer == + pseudo_self.deref() as *ContainerLayer); }, _ => fail!(~"Invalid parent of child in layer tree"), } match child_common.next_sibling { None => { // this is the last child - pseudo_self.borrow().last_child.set(child_common.prev_sibling.clone()); + pseudo_self.last_child.set(child_common.prev_sibling.clone()); }, Some(ref sibling) => { sibling.with_common(|sibling_common| { @@ -204,7 +195,7 @@ impl ContainerLayer { } match child_common.prev_sibling { None => { // this is the first child - pseudo_self.borrow().first_child.set(child_common.next_sibling.clone()); + pseudo_self.first_child.set(child_common.next_sibling.clone()); }, Some(ref sibling) => { sibling.with_common(|sibling_common| { diff --git a/rendergl.rs b/rendergl.rs index 5a03892..026ae93 100755 --- a/rendergl.rs +++ b/rendergl.rs @@ -475,10 +475,10 @@ fn render_layer(render_context: RenderContext, layer: layers::Layer) { match layer { ContainerLayerKind(container_layer) => { - container_layer.borrow().render(render_context, transform, scene_size) + container_layer.render(render_context, transform, scene_size) } TextureLayerKind(texture_layer) => { - texture_layer.borrow().render(render_context, transform, scene_size) + texture_layer.render(render_context, transform, scene_size) } } } From ea031c23af5133afec9e86f5c35220b9cac3f5ee Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 22 Mar 2014 11:28:31 +0100 Subject: [PATCH 3/5] Update to current rust: don't use libextra. --- lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/lib.rs b/lib.rs index f98cea5..3f4f42c 100755 --- a/lib.rs +++ b/lib.rs @@ -11,7 +11,6 @@ #[feature(managed_boxes)]; -extern crate extra; extern crate geom; extern crate opengles; extern crate std; From 2ad0d8a759ef9d1564bee90852b89d831e7abf7e Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sun, 23 Mar 2014 19:43:31 +0100 Subject: [PATCH 4/5] Update to current rust: stop using Ref::get(). --- layers.rs | 6 ++---- rendergl.rs | 10 ++++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/layers.rs b/layers.rs index 89d3942..67ddb40 100644 --- a/layers.rs +++ b/layers.rs @@ -30,12 +30,10 @@ impl Layer { pub fn with_common(&self, f: |&mut CommonLayer| -> T) -> T { match *self { ContainerLayerKind(ref container_layer) => { - let mut tmp = container_layer.common.borrow_mut(); - f(tmp.get()) + f(&mut *container_layer.common.borrow_mut()) }, TextureLayerKind(ref texture_layer) => { - let mut tmp = texture_layer.common.borrow_mut(); - f(tmp.get()) + f(&mut *texture_layer.common.borrow_mut()) }, } } diff --git a/rendergl.rs b/rendergl.rs index 026ae93..5e0be51 100755 --- a/rendergl.rs +++ b/rendergl.rs @@ -370,9 +370,7 @@ impl Render for layers::ContainerLayer { None }; - // NOTE: work around borrowchk - let tmp = self.scissor.borrow(); - match tmp.get() { + match &*self.scissor.borrow() { &Some(rect) => { let size = Size2D((rect.size.width * transform.m11) as GLint, (rect.size.height * transform.m22) as GLint); @@ -434,7 +432,7 @@ impl Render for layers::ContainerLayer { // NOTE: work around borrowchk { let tmp = self.common.borrow(); - let transform = transform.mul(&tmp.get().transform); + let transform = transform.mul(&tmp.transform); for child in self.children() { render_layer(render_context, transform, scene_size, child); } @@ -442,7 +440,7 @@ impl Render for layers::ContainerLayer { // NOTE: work around borrowchk let tmp = self.scissor.borrow(); - match (tmp.get(), old_rect_opt) { + match (&*tmp, old_rect_opt) { (&Some(_), Some(old_rect)) => { // Set scissor back to the parent's scissoring rect. scissor(old_rect.origin.x, old_rect.origin.y, @@ -464,7 +462,7 @@ impl Render for layers::TextureLayer { transform: Matrix4, scene_size: Size2D) { let tmp = self.common.borrow(); - let transform = transform.mul(&tmp.get().transform); + let transform = transform.mul(&tmp.transform); bind_and_render_quad(render_context, &self.texture, self.flip, &transform, scene_size); } } From d95443207a0880c8a5a6eb2aa5cdf280bcb932ae Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sun, 23 Mar 2014 19:46:04 +0100 Subject: [PATCH 5/5] Update to current rust: stop using RefCell::with_mut(). --- layers.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/layers.rs b/layers.rs index 67ddb40..a57e1be 100644 --- a/layers.rs +++ b/layers.rs @@ -161,12 +161,11 @@ impl ContainerLayer { pseudo_self.last_child.set(Some(new_child.clone())); - pseudo_self.first_child.with_mut(|child| { - match *child { - Some(_) => {}, - None => *child = Some(new_child.clone()), - } - }); + let mut child = pseudo_self.first_child.borrow_mut(); + match *child { + Some(_) => {}, + None => *child = Some(new_child.clone()), + } }); }