Merge pull request #55 from dcbishop/vec

Replace some ~[]'s with Vec.
This commit is contained in:
Tony Aldridge
2014-03-17 10:50:31 +00:00
11 changed files with 49 additions and 38 deletions
+9 -7
View File
@@ -3,24 +3,25 @@
use std::io::BufferedWriter;
use std::io::{File, Writer};
use std::str::Chars;
use std::vec_ng::Vec;
struct ParseBranch {
matches: ~[u8],
matches: Vec<u8>,
result: Option<~str>,
children: ~[ParseBranch],
children: Vec<ParseBranch>,
}
impl ParseBranch {
fn new() -> ParseBranch {
ParseBranch {
matches: ~[],
matches: Vec::new(),
result: None,
children: ~[],
children: Vec::new(),
}
}
}
pub fn branchify(options: &[(&str, &str)], case_sensitive: bool) -> ~[ParseBranch] {
pub fn branchify(options: &[(&str, &str)], case_sensitive: bool) -> Vec<ParseBranch> {
let mut root = ParseBranch::new();
fn go_down_moses(branch: &mut ParseBranch, mut chariter: Chars, result: &str, case_sensitive: bool) {
@@ -28,7 +29,7 @@ pub fn branchify(options: &[(&str, &str)], case_sensitive: bool) -> ~[ParseBranc
Some(c) => {
let first_case = if case_sensitive { c as u8 } else { c.to_ascii().to_upper().to_byte() };
for next_branch in branch.children.mut_iter() {
if next_branch.matches[0] == first_case {
if next_branch.matches.as_slice()[0] == first_case {
go_down_moses(next_branch, chariter, result, case_sensitive);
return;
}
@@ -42,7 +43,8 @@ pub fn branchify(options: &[(&str, &str)], case_sensitive: bool) -> ~[ParseBranc
}
}
branch.children.push(subbranch);
go_down_moses(&mut branch.children[branch.children.len() - 1], chariter, result, case_sensitive);
let index = branch.children.len() -1;
go_down_moses(&mut branch.children.as_mut_slice()[index], chariter, result, case_sensitive);
},
None => {
assert!(branch.result.is_none());
+2 -2
View File
@@ -1,6 +1,6 @@
extern crate extra;
use std::io::Writer;
use super::get_writer;
use std::vec_ng::Vec;
struct Key {
code: uint,
@@ -348,7 +348,7 @@ impl KeyCode {
impl ToPrimitive for KeyCode {
/// Equivalent to `self.code()`
".as_bytes());
let types = ~["i64", "u64", "int"];
let types = vec!("i64", "u64", "int");
for primitive_type in types.iter() {
out.write(format!("fn to_{}(&self) -> Option<{}> \\{
Some(self.code() as {})
+7 -6
View File
@@ -8,33 +8,34 @@ use std::io;
use std::io::stdio::println;
use std::io::fs::mkdir_recursive;
use std::path::GenericPath;
use std::vec_ng::Vec;
pub mod branchify;
pub mod keycode;
pub mod scancode;
fn main() {
let args = os::args();
let args = Vec::from_slice(os::args());
match args.len() {
0 => {
println("usage: codegen [keycode|scancode].rs destdir");
os::set_exit_status(1);
},
3 => {
let output_dir = GenericPath::new(args[2].clone());
let output_dir = GenericPath::new(args.get(2).clone());
// TODO: maybe not 0777?
mkdir_recursive(&output_dir, 0b111_111_111);
if args[1] == ~"keycode.rs" {
if *args.get(1) == ~"keycode.rs" {
keycode::generate(&output_dir);
} else if args[1] == ~"scancode.rs" {
} else if *args.get(1) == ~"scancode.rs" {
scancode::generate(&output_dir);
} else {
println!("unknown thing-to-generate '{}'", args[1]);
println!("unknown thing-to-generate '{}'", args.get(1));
os::set_exit_status(1);
}
},
_ => {
println!("usage: {} [keycode|scancode].rs destdir", args[0]);
println!("usage: {} [keycode|scancode].rs destdir", args.get(0));
os::set_exit_status(1);
}
}
+2 -2
View File
@@ -1,6 +1,6 @@
extern crate extra;
use std::io::Writer;
use super::get_writer;
use std::vec_ng::Vec;
struct ScanCode {
code: uint,
@@ -355,7 +355,7 @@ impl ToPrimitive for ScanCode {
/// Equivalent to `self.code()`
".as_bytes());
let types = ~["i64", "u64", "int"];
let types = vec!("i64", "u64", "int");
for primitive_type in types.iter() {
out.write(format!("fn to_{}(&self) -> Option<{}> \\{
Some(self.code() as {})
+7 -4
View File
@@ -2,6 +2,7 @@ use std::cast;
use std::libc::{c_int, c_void, uint32_t};
use std::num::FromPrimitive;
use std::str;
use std::vec_ng::Vec;
use controller;
use controller::{ControllerAxis, ControllerButton};
@@ -524,12 +525,12 @@ pub enum Event {
WindowEvent(uint, ~video::Window, WindowEventId, int, int),
// TODO: SysWMEvent
KeyDownEvent(uint, ~video::Window, KeyCode, ScanCode, ~[Mod]),
KeyUpEvent(uint, ~video::Window, KeyCode, ScanCode, ~[Mod]),
KeyDownEvent(uint, ~video::Window, KeyCode, ScanCode, Vec<Mod>),
KeyUpEvent(uint, ~video::Window, KeyCode, ScanCode, Vec<Mod>),
TextEditingEvent(uint, ~video::Window, ~str, int, int),
TextInputEvent(uint, ~video::Window, ~str),
MouseMotionEvent(uint, ~video::Window, uint, ~[MouseState], int, int,
MouseMotionEvent(uint, ~video::Window, uint, Vec<MouseState>, int, int,
int, int),
MouseButtonDownEvent(uint, ~video::Window, uint, Mouse, int, int),
MouseButtonUpEvent(uint, ~video::Window, uint, Mouse, int, int),
@@ -537,7 +538,7 @@ pub enum Event {
JoyAxisMotionEvent(uint, int, int, i16),
JoyBallMotionEvent(uint, int, i16, i16),
JoyHatMotionEvent(uint, int, int, ~[HatState]),
JoyHatMotionEvent(uint, int, int, Vec<HatState>),
JoyButtonDownEvent(uint, int, int),
JoyButtonUpEvent(uint, int, int),
JoyDeviceAddedEvent(uint, int),
@@ -566,6 +567,8 @@ pub enum Event {
impl Event {
}
// TODO: Remove this when from_utf8 is updated in Rust
#[allow(deprecated_owned_vector)]
fn wrap_event(raw: ll::SDL_Event) -> Event {
unsafe {
let raw_type = raw._type();
+2 -1
View File
@@ -1,3 +1,4 @@
use std::vec_ng::Vec;
#[allow(non_camel_case_types)]
pub mod ll {
@@ -53,7 +54,7 @@ pub enum HatState {
LeftHatState
}
pub fn wrap_hat_state(bitflags: u8) -> ~[HatState] {
pub fn wrap_hat_state(bitflags: u8) -> Vec<HatState> {
let flags = [CenteredHatState,
UpHatState,
RightHatState,
+3 -2
View File
@@ -3,6 +3,7 @@ use std::num::FromPrimitive;
use std::ptr;
use std::str;
use std::vec;
use std::vec_ng::Vec;
use keycode::KeyCode;
use rect::Rect;
@@ -67,7 +68,7 @@ pub enum Mod {
ReservedMod = 0x8000
}
pub fn wrap_mod_state(bitflags: ll::SDL_Keymod) -> ~[Mod] {
pub fn wrap_mod_state(bitflags: ll::SDL_Keymod) -> Vec<Mod> {
let flags = [NoMod,
LShiftMod,
RShiftMod,
@@ -114,7 +115,7 @@ pub fn get_keyboard_state() -> ~HashMap<ScanCode, bool> {
return state;
}
pub fn get_mod_state() -> ~[Mod] {
pub fn get_mod_state() -> Vec<Mod> {
unsafe { wrap_mod_state(ll::SDL_GetModState()) }
}
+4 -3
View File
@@ -1,4 +1,5 @@
use std::ptr;
use std::vec_ng::Vec;
use get_error;
use surface;
@@ -161,7 +162,7 @@ pub fn wrap_mouse(bitflags: u8) -> Mouse {
}
}
pub fn wrap_mouse_state(bitflags: u32) -> ~[MouseState] {
pub fn wrap_mouse_state(bitflags: u32) -> Vec<MouseState> {
let flags = [LeftMouseState,
MiddleMouseState,
RightMouseState,
@@ -183,7 +184,7 @@ pub fn get_mouse_focus() -> Option<~video::Window> {
}
}
pub fn get_mouse_state() -> (~[MouseState], int, int) {
pub fn get_mouse_state() -> (Vec<MouseState>, int, int) {
let x = 0;
let y = 0;
let raw = unsafe { ll::SDL_GetMouseState(&x, &y) };
@@ -191,7 +192,7 @@ pub fn get_mouse_state() -> (~[MouseState], int, int) {
return (wrap_mouse_state(raw), x as int, y as int);
}
pub fn get_relative_mouse_state() -> (~[MouseState], int, int) {
pub fn get_relative_mouse_state() -> (Vec<MouseState>, int, int) {
let x = 0;
let y = 0;
let raw = unsafe { ll::SDL_GetRelativeMouseState(&x, &y) };
+4 -3
View File
@@ -9,6 +9,7 @@ use std::cast;
use rect::Point;
use rect::Rect;
use std::num::FromPrimitive;
use std::vec_ng::Vec;
#[allow(non_camel_case_types)]
pub mod ll {
@@ -155,8 +156,8 @@ pub enum RendererFlags {
#[deriving(Eq)]
pub struct RendererInfo {
name: ~str,
flags: ~[RendererFlags],
texture_formats: ~[pixels::PixelFormatFlag],
flags: Vec<RendererFlags>,
texture_formats: Vec<pixels::PixelFormatFlag>,
max_texture_width: int,
max_texture_height: int
}
@@ -192,7 +193,7 @@ impl RendererInfo {
}).collect();
unsafe {
let texture_formats: ~[pixels::PixelFormatFlag] = info.texture_formats.slice(0, info.num_texture_formats as uint).iter().map(|&format| {
let texture_formats: Vec<pixels::PixelFormatFlag> = info.texture_formats.slice(0, info.num_texture_formats as uint).iter().map(|&format| {
FromPrimitive::from_i64(format as i64).unwrap()
}).collect();
+2 -1
View File
@@ -1,5 +1,6 @@
use std::cast;
use std::str;
use std::vec_ng::Vec;
// Setup linking for all targets.
#[cfg(target_os="macos")]
@@ -113,7 +114,7 @@ pub fn quit() {
unsafe { ll::SDL_Quit(); }
}
pub fn was_inited(flags: &[InitFlag]) -> ~[InitFlag] {
pub fn was_inited(flags: &[InitFlag]) -> Vec<InitFlag> {
let flags = flags.iter().fold(0u32, |flags, &flag| {
flags | flag as ll::SDL_InitFlag
});
+7 -7
View File
@@ -2,7 +2,7 @@ use std::libc::{c_int, c_float, uint32_t};
use std::ptr;
use std::str;
use std::cast;
use std::vec;
use std::vec_ng::Vec;
use rect::Rect;
use surface::Surface;
@@ -282,7 +282,7 @@ pub enum FullscreenType {
}
fn wrap_window_flags(bitflags: u32) -> ~[WindowFlags] {
fn wrap_window_flags(bitflags: u32) -> Vec<WindowFlags> {
let flags = [
Fullscreen,
OpenGL,
@@ -432,7 +432,7 @@ impl Window {
unsafe { ll::SDL_GetWindowID(self.raw) }
}
pub fn get_flags(&self) -> ~[WindowFlags] {
pub fn get_flags(&self) -> Vec<WindowFlags> {
let raw = unsafe { ll::SDL_GetWindowFlags(self.raw) };
wrap_window_flags(raw)
}
@@ -585,10 +585,10 @@ impl Window {
}
}
pub fn get_gamma_ramp(&self) -> Result<(~[u16], ~[u16], ~[u16]), ~str> {
let red: ~[u16] = vec::with_capacity(256);
let green: ~[u16] = vec::with_capacity(256);
let blue: ~[u16] = vec::with_capacity(256);
pub fn get_gamma_ramp(&self) -> Result<(Vec<u16>, Vec<u16>, Vec<u16>), ~str> {
let red: Vec<u16> = Vec::with_capacity(256);
let green: Vec<u16> = Vec::with_capacity(256);
let blue: Vec<u16> = Vec::with_capacity(256);
let result = unsafe {ll::SDL_GetWindowGammaRamp(self.raw, cast::transmute(red.as_ptr()), cast::transmute(green.as_ptr()), cast::transmute(blue.as_ptr())) == 0};
if result {
Ok((red, green, blue))