Put the swizzle operators behind a feature flag "swizzle" to avoid increasing

the binary size by approximately 20% by default.
This commit is contained in:
Egor Larionov 2017-10-01 13:26:47 -07:00
parent 768b6b71f0
commit 12547b5bcb
2 changed files with 16 additions and 7 deletions

View file

@ -18,6 +18,7 @@ name = "cgmath"
[features]
unstable = []
swizzle = []
[dependencies]
approx = "0.1"

View file

@ -6,6 +6,7 @@ use std::string::String;
/// Generate the name of the swizzle function and what it returns.
/// NOTE: This function assumes that variables are in ASCII format
#[cfg(feature = "swizzle")]
fn gen_swizzle_nth<'a>(variables: &'a str, mut i: usize, upto: usize) -> Option<(String, String)> {
debug_assert!(i > 0); // zeroth permutation is empty
let mut swizzle_impl = String::new();
@ -27,6 +28,7 @@ fn gen_swizzle_nth<'a>(variables: &'a str, mut i: usize, upto: usize) -> Option<
/// `upto`: largest output vector size (e.g. for `variables = "xy"` and `upto = 4`, `xyxy()` is a
/// valid swizzle operator.
/// NOTE: This function assumes that variables are in ASCII format
#[cfg(feature = "swizzle")]
fn gen_swizzle_functions(variables: &'static str, upto: usize) -> String {
let mut result = String::new();
let nn = (variables.len()+1).pow(upto as u32);
@ -43,6 +45,12 @@ fn gen_swizzle_functions(variables: &'static str, upto: usize) -> String {
result
}
#[cfg(not(feature = "swizzle"))]
fn gen_swizzle_functions(_: &'static str, _: usize) -> String {
String::new()
}
/// This script generates the macro for building swizzle operators for multidimensional
/// vectors and points. This macro is included in macros.rs
fn main() {