From de705e9c95192f166996dc9cbc5d0df96557ef11 Mon Sep 17 00:00:00 2001 From: Lionel Flandrin Date: Sat, 9 Jan 2016 21:49:16 +0100 Subject: [PATCH] Use ArrayVec to avoid dynamic allocations --- Cargo.lock | 39 +++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/lib.rs | 1 + src/retrogl/gl_state.rs | 5 +++-- 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2d8282d..a86df45 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,7 @@ name = "rustation-retro" version = "0.1.0" dependencies = [ + "arrayvec 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", "gl 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -17,6 +18,15 @@ dependencies = [ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "arrayvec" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "nodrop 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "odds 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "bitflags" version = "0.3.3" @@ -59,6 +69,22 @@ dependencies = [ "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "nodrop" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "odds 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "odds" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unreachable 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rand" version = "0.3.12" @@ -91,6 +117,19 @@ dependencies = [ "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "unreachable" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "void 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "void" +version = "0.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "winapi" version = "0.2.5" diff --git a/Cargo.toml b/Cargo.toml index a400a7e..9417b5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ keywords = ["emulator", "playstation"] libc = "0.2.4" gl = "0.5.2" log = "0.3.4" +arrayvec = "0.3.12" [lib] name = "rustation_retro" diff --git a/src/lib.rs b/src/lib.rs index f0fd193..5bdc3d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,6 +20,7 @@ extern crate gl; #[macro_use] extern crate log; extern crate rustation; +extern crate arrayvec; macro_rules! cstring { ($x:expr) => { diff --git a/src/retrogl/gl_state.rs b/src/retrogl/gl_state.rs index c517f73..ba3bade 100644 --- a/src/retrogl/gl_state.rs +++ b/src/retrogl/gl_state.rs @@ -1,5 +1,6 @@ use gl; use gl::types::{GLuint, GLint}; +use arrayvec::ArrayVec; use rustation::gpu::renderer::{Renderer, Vertex}; use retrogl::{State, DrawConfig}; @@ -103,7 +104,7 @@ impl Renderer for GlState { self.draw().unwrap(); } - let v: Vec<_> = + let v: ArrayVec<[_; 3]> = vertices.iter().map(|v| CommandVertex::from_vertex(v)) .collect(); @@ -115,7 +116,7 @@ impl Renderer for GlState { self.draw().unwrap(); } - let v: Vec<_> = + let v: ArrayVec<[_; 4]> = vertices.iter().map(|v| CommandVertex::from_vertex(v)) .collect();