Use ArrayVec to avoid dynamic allocations

This commit is contained in:
Lionel Flandrin 2016-01-09 21:49:16 +01:00
parent 0cff516294
commit de705e9c95
4 changed files with 44 additions and 2 deletions

39
Cargo.lock generated
View File

@ -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"

View File

@ -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"

View File

@ -20,6 +20,7 @@ extern crate gl;
#[macro_use]
extern crate log;
extern crate rustation;
extern crate arrayvec;
macro_rules! cstring {
($x:expr) => {

View File

@ -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();