Skip to content

Commit 9c5bec4

Browse files
committed
EncodeArguments trait doesn't allocate anymore.
1 parent 045a49d commit 9c5bec4

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

src/declare.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@ pub trait MethodImplementation {
8080
fn imp_for(self, sel: Sel) -> Result<Imp, UnequalArgsError>;
8181
}
8282

83-
macro_rules! count_idents {
84-
() => (0);
85-
($a:ident) => (1);
86-
($a:ident, $($b:ident),+) => (1 + count_idents!($($b),*));
87-
}
88-
8983
macro_rules! method_decl_impl {
9084
(-$s:ident, $r:ident, $f:ty, $($t:ident),*) => (
9185
impl<$s, $r $(, $t)*> MethodImplementation for $f
@@ -128,7 +122,7 @@ method_decl_impl!(A, B, C, D, E, F, G, H, I, J, K, L);
128122

129123
fn method_type_encoding<F>() -> CString where F: MethodImplementation {
130124
let mut types = F::Ret::encode().as_str().to_owned();
131-
types.extend(F::Args::encodings().iter().map(|e| e.as_str()));
125+
types.extend(F::Args::encodings().as_ref().iter().map(|e| e.as_str()));
132126
CString::new(types).unwrap()
133127
}
134128

src/macros.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ macro_rules! objc_try {
102102
($b:block) => ($b)
103103
}
104104

105+
macro_rules! count_idents {
106+
() => (0);
107+
($a:ident) => (1);
108+
($a:ident, $($b:ident),+) => (1 + count_idents!($($b),*));
109+
}
110+
105111
macro_rules! encode {
106112
() => ("");
107113
(i8 $($x:tt)*) => (concat!("c", encode!($($x)*)));

src/verify.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@ use runtime::{Class, Object, Sel};
44
use {Encode, Encoding};
55

66
pub trait EncodeArguments {
7-
fn encodings() -> Box<[Encoding]>;
7+
type Encs: AsRef<[Encoding]>;
8+
9+
fn encodings() -> Self::Encs;
810
}
911

1012
macro_rules! encode_args_impl {
1113
($($t:ident),*) => (
1214
impl<$($t: Encode),*> EncodeArguments for ($($t,)*) {
13-
fn encodings() -> Box<[Encoding]> {
14-
Box::new([
15+
type Encs = [Encoding; 2 + count_idents!($($t),*)];
16+
17+
fn encodings() -> Self::Encs {
18+
[
1519
<*mut Object>::encode(),
1620
Sel::encode(),
1721
$($t::encode()),*
18-
])
22+
]
1923
}
2024
}
2125
);
@@ -51,6 +55,7 @@ pub fn verify_message_signature<A, R>(cls: &Class, sel: Sel) -> Result<(), Strin
5155
}
5256

5357
let args = A::encodings();
58+
let args = args.as_ref();
5459
let count = args.len();
5560
let expected_count = method.arguments_count();
5661
if count != expected_count {

0 commit comments

Comments
 (0)