I saw some comments on macros defined in Rust std such as:
saying that they "make a huge performance difference" (compared to inline functions).
But as I understand, macros and inline functions (small and simple enough to be inlined) result in roughly the same code after preprocessed & compiled, and it seems they are in fact small enough. (the iterator
macro might be considered fairly large (?), but other macros that are used there are small)
For example, I thought an inline function like this one:
#[inline(always)]
fn is_empty<'a, T>(iter: Iter<'a, T>) -> bool {
if T::IS_ZST {
iter.end.addr() == 0
} else {
iter.ptr.as_ptr() as *const _ == iter.end
}
}
would work equally as:
macro_rules! is_empty {
($self: ident) => {
if T::IS_ZST { $self.end.addr() == 0 } else { $self.ptr.as_ptr() as *const _ == $self.end }
};
}
when used in e.g., /src/core/slice/iter.rs.html#129-137 (sorry I can't put more than 2 links)
So my question is: where could the "huge" difference come from?