Skip to content

Commit 8e8fd02

Browse files
committed
Factorize some macros in iter/range.rs
1 parent d1ec6c2 commit 8e8fd02

File tree

1 file changed

+28
-57
lines changed

1 file changed

+28
-57
lines changed

src/libcore/iter/range.rs

+28-57
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,31 @@ pub trait Step: PartialOrd + Sized {
4242
fn sub_one(&self) -> Self;
4343
}
4444

45+
// These are still macro-generated because the integer literals resolve to different types.
46+
macro_rules! step_identical_methods {
47+
() => {
48+
#[inline]
49+
fn replace_one(&mut self) -> Self {
50+
mem::replace(self, 1)
51+
}
52+
53+
#[inline]
54+
fn replace_zero(&mut self) -> Self {
55+
mem::replace(self, 0)
56+
}
57+
58+
#[inline]
59+
fn add_one(&self) -> Self {
60+
Add::add(*self, 1)
61+
}
62+
63+
#[inline]
64+
fn sub_one(&self) -> Self {
65+
Sub::sub(*self, 1)
66+
}
67+
}
68+
}
69+
4570
macro_rules! step_impl_unsigned {
4671
($($t:ty)*) => ($(
4772
#[unstable(feature = "step_trait",
@@ -59,25 +84,7 @@ macro_rules! step_impl_unsigned {
5984
}
6085
}
6186

62-
#[inline]
63-
fn replace_one(&mut self) -> Self {
64-
mem::replace(self, 1)
65-
}
66-
67-
#[inline]
68-
fn replace_zero(&mut self) -> Self {
69-
mem::replace(self, 0)
70-
}
71-
72-
#[inline]
73-
fn add_one(&self) -> Self {
74-
Add::add(*self, 1)
75-
}
76-
77-
#[inline]
78-
fn sub_one(&self) -> Self {
79-
Sub::sub(*self, 1)
80-
}
87+
step_identical_methods!();
8188
}
8289
)*)
8390
}
@@ -100,25 +107,7 @@ macro_rules! step_impl_signed {
100107
}
101108
}
102109

103-
#[inline]
104-
fn replace_one(&mut self) -> Self {
105-
mem::replace(self, 1)
106-
}
107-
108-
#[inline]
109-
fn replace_zero(&mut self) -> Self {
110-
mem::replace(self, 0)
111-
}
112-
113-
#[inline]
114-
fn add_one(&self) -> Self {
115-
Add::add(*self, 1)
116-
}
117-
118-
#[inline]
119-
fn sub_one(&self) -> Self {
120-
Sub::sub(*self, 1)
121-
}
110+
step_identical_methods!();
122111
}
123112
)*)
124113
}
@@ -134,25 +123,7 @@ macro_rules! step_impl_no_between {
134123
None
135124
}
136125

137-
#[inline]
138-
fn replace_one(&mut self) -> Self {
139-
mem::replace(self, 1)
140-
}
141-
142-
#[inline]
143-
fn replace_zero(&mut self) -> Self {
144-
mem::replace(self, 0)
145-
}
146-
147-
#[inline]
148-
fn add_one(&self) -> Self {
149-
Add::add(*self, 1)
150-
}
151-
152-
#[inline]
153-
fn sub_one(&self) -> Self {
154-
Sub::sub(*self, 1)
155-
}
126+
step_identical_methods!();
156127
}
157128
)*)
158129
}

0 commit comments

Comments
 (0)