Skip to content

Commit

Permalink
Precompute rust types, and reduce heap allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanzab committed Dec 19, 2015
1 parent 116623c commit 9ab12cb
Show file tree
Hide file tree
Showing 10 changed files with 777 additions and 806 deletions.
2 changes: 1 addition & 1 deletion gl_generator/generators/debug_struct_gen.rs
Expand Up @@ -219,7 +219,7 @@ fn write_impl<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W: i
name = cmd.proto.ident,
params = super::gen_parameters(cmd, true, true).join(", "),
typed_params = typed_params.join(", "),
return_suffix = super::gen_return_type(cmd),
return_suffix = cmd.proto.ty,
idents = idents.join(", "),
println = println,
print_err = if cmd.proto.ident != "GetError" && registry.cmds.iter().find(|cmd| cmd.proto.ident == "GetError").is_some() {
Expand Down
14 changes: 7 additions & 7 deletions gl_generator/generators/global_gen.rs
Expand Up @@ -97,8 +97,8 @@ fn write_enums<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W:
/// The function calls the corresponding function pointer stored in the `storage` module created
/// by `write_ptrs`.
fn write_fns<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W: io::Write {
for c in &registry.cmds {
if let Some(v) = registry.aliases.get(&c.proto.ident) {
for cmd in &registry.cmds {
if let Some(v) = registry.aliases.get(&cmd.proto.ident) {
try!(writeln!(dest, "/// Fallbacks: {}", v.join(", ")));
}

Expand All @@ -108,11 +108,11 @@ fn write_fns<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W: io
__gl_imports::mem::transmute::<_, extern \"system\" fn({typed_params}) -> {return_suffix}>\
(storage::{name}.f)({idents}) \
}}",
name = c.proto.ident,
params = super::gen_parameters(c, true, true).join(", "),
typed_params = super::gen_parameters(c, false, true).join(", "),
return_suffix = super::gen_return_type(c),
idents = super::gen_parameters(c, true, false).join(", "),
name = cmd.proto.ident,
params = super::gen_parameters(cmd, true, true).join(", "),
typed_params = super::gen_parameters(cmd, false, true).join(", "),
return_suffix = cmd.proto.ty,
idents = super::gen_parameters(cmd, true, false).join(", "),
));
}

Expand Down
507 changes: 485 additions & 22 deletions gl_generator/generators/mod.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gl_generator/generators/static_gen.rs
Expand Up @@ -82,7 +82,7 @@ fn write_fns<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W: io
symbol = super::gen_symbol_name(registry.api, &cmd.proto.ident),
name = cmd.proto.ident,
params = super::gen_parameters(cmd, true, true).join(", "),
return_suffix = super::gen_return_type(cmd)
return_suffix = cmd.proto.ty,
));
}

Expand Down
4 changes: 2 additions & 2 deletions gl_generator/generators/static_struct_gen.rs
Expand Up @@ -104,7 +104,7 @@ fn write_impl<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W: i
}}",
name = cmd.proto.ident,
typed_params = super::gen_parameters(cmd, true, true).join(", "),
return_suffix = super::gen_return_type(cmd),
return_suffix = cmd.proto.ty,
idents = super::gen_parameters(cmd, true, false).join(", "),
));
}
Expand All @@ -129,7 +129,7 @@ fn write_fns<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W: io
symbol = super::gen_symbol_name(registry.api, &cmd.proto.ident),
name = cmd.proto.ident,
params = super::gen_parameters(cmd, true, true).join(", "),
return_suffix = super::gen_return_type(cmd)
return_suffix = cmd.proto.ty,
));
}

Expand Down
2 changes: 1 addition & 1 deletion gl_generator/generators/struct_gen.rs
Expand Up @@ -202,7 +202,7 @@ fn write_impl<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W: i
name = cmd.proto.ident,
params = super::gen_parameters(cmd, true, true).join(", "),
typed_params = super::gen_parameters(cmd, false, true).join(", "),
return_suffix = super::gen_return_type(cmd),
return_suffix = cmd.proto.ty,
idents = super::gen_parameters(cmd, true, false).join(", "),
))
}
Expand Down
758 changes: 0 additions & 758 deletions gl_generator/generators/ty.rs

This file was deleted.

9 changes: 5 additions & 4 deletions gl_generator/registry/mod.rs
Expand Up @@ -14,6 +14,7 @@

extern crate khronos_api;

use std::borrow::Cow;
use std::collections::BTreeSet;
use std::collections::HashMap;
use std::fmt;
Expand Down Expand Up @@ -58,7 +59,7 @@ pub struct Enum {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Binding {
pub ident: String,
pub ty: String,
pub ty: Cow<'static, str>,
}

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -121,12 +122,12 @@ impl Registry {

/// Returns a set of all the types used in the supplied registry. This is useful
/// for working out what conversions are needed for the specific registry.
pub fn get_tys(&self) -> BTreeSet<String> {
pub fn get_tys(&self) -> BTreeSet<&str> {
let mut tys = BTreeSet::new();
for def in &self.cmds {
tys.insert(def.proto.ty.clone());
tys.insert(def.proto.ty.as_ref());
for param in &def.params {
tys.insert(param.ty.clone());
tys.insert(param.ty.as_ref());
}
}
tys
Expand Down

0 comments on commit 9ab12cb

Please sign in to comment.