Skip to content

Commit 939a97f

Browse files
committed
Add #[inline(always)] to each operator method
1 parent d2a81b9 commit 939a97f

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

src/libcore/num/f32.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,26 +288,32 @@ impl num::One for f32 {
288288

289289
#[cfg(notest)]
290290
impl ops::Add<f32,f32> for f32 {
291+
#[inline(always)]
291292
fn add(&self, other: &f32) -> f32 { *self + *other }
292293
}
293294
#[cfg(notest)]
294295
impl ops::Sub<f32,f32> for f32 {
296+
#[inline(always)]
295297
fn sub(&self, other: &f32) -> f32 { *self - *other }
296298
}
297299
#[cfg(notest)]
298300
impl ops::Mul<f32,f32> for f32 {
301+
#[inline(always)]
299302
fn mul(&self, other: &f32) -> f32 { *self * *other }
300303
}
301304
#[cfg(notest)]
302305
impl ops::Div<f32,f32> for f32 {
306+
#[inline(always)]
303307
fn div(&self, other: &f32) -> f32 { *self / *other }
304308
}
305309
#[cfg(notest)]
306310
impl ops::Modulo<f32,f32> for f32 {
311+
#[inline(always)]
307312
fn modulo(&self, other: &f32) -> f32 { *self % *other }
308313
}
309314
#[cfg(notest)]
310315
impl ops::Neg<f32> for f32 {
316+
#[inline(always)]
311317
fn neg(&self) -> f32 { -*self }
312318
}
313319

src/libcore/num/f64.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,26 +310,32 @@ impl num::One for f64 {
310310

311311
#[cfg(notest)]
312312
impl ops::Add<f64,f64> for f64 {
313+
#[inline(always)]
313314
fn add(&self, other: &f64) -> f64 { *self + *other }
314315
}
315316
#[cfg(notest)]
316317
impl ops::Sub<f64,f64> for f64 {
318+
#[inline(always)]
317319
fn sub(&self, other: &f64) -> f64 { *self - *other }
318320
}
319321
#[cfg(notest)]
320322
impl ops::Mul<f64,f64> for f64 {
323+
#[inline(always)]
321324
fn mul(&self, other: &f64) -> f64 { *self * *other }
322325
}
323326
#[cfg(notest)]
324327
impl ops::Div<f64,f64> for f64 {
328+
#[inline(always)]
325329
fn div(&self, other: &f64) -> f64 { *self / *other }
326330
}
327331
#[cfg(notest)]
328332
impl ops::Modulo<f64,f64> for f64 {
333+
#[inline(always)]
329334
fn modulo(&self, other: &f64) -> f64 { *self % *other }
330335
}
331336
#[cfg(notest)]
332337
impl ops::Neg<f64> for f64 {
338+
#[inline(always)]
333339
fn neg(&self) -> f64 { -*self }
334340
}
335341

src/libcore/num/float.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,15 +387,21 @@ pub fn tan(x: float) -> float {
387387
388388
#[cfg(notest)]
389389
impl Eq for float {
390+
#[inline(always)]
390391
fn eq(&self, other: &float) -> bool { (*self) == (*other) }
392+
#[inline(always)]
391393
fn ne(&self, other: &float) -> bool { (*self) != (*other) }
392394
}
393395
394396
#[cfg(notest)]
395397
impl Ord for float {
398+
#[inline(always)]
396399
fn lt(&self, other: &float) -> bool { (*self) < (*other) }
400+
#[inline(always)]
397401
fn le(&self, other: &float) -> bool { (*self) <= (*other) }
402+
#[inline(always)]
398403
fn ge(&self, other: &float) -> bool { (*self) >= (*other) }
404+
#[inline(always)]
399405
fn gt(&self, other: &float) -> bool { (*self) > (*other) }
400406
}
401407
@@ -444,26 +450,32 @@ impl num::Round for float {
444450
445451
#[cfg(notest)]
446452
impl ops::Add<float,float> for float {
453+
#[inline(always)]
447454
fn add(&self, other: &float) -> float { *self + *other }
448455
}
449456
#[cfg(notest)]
450457
impl ops::Sub<float,float> for float {
458+
#[inline(always)]
451459
fn sub(&self, other: &float) -> float { *self - *other }
452460
}
453461
#[cfg(notest)]
454462
impl ops::Mul<float,float> for float {
463+
#[inline(always)]
455464
fn mul(&self, other: &float) -> float { *self * *other }
456465
}
457466
#[cfg(notest)]
458467
impl ops::Div<float,float> for float {
468+
#[inline(always)]
459469
fn div(&self, other: &float) -> float { *self / *other }
460470
}
461471
#[cfg(notest)]
462472
impl ops::Modulo<float,float> for float {
473+
#[inline(always)]
463474
fn modulo(&self, other: &float) -> float { *self % *other }
464475
}
465476
#[cfg(notest)]
466477
impl ops::Neg<float> for float {
478+
#[inline(always)]
467479
fn neg(&self) -> float { -*self }
468480
}
469481

src/libcore/num/int-template.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,50 +177,63 @@ impl num::One for T {
177177
178178
#[cfg(notest)]
179179
impl ops::Add<T,T> for T {
180+
#[inline(always)]
180181
fn add(&self, other: &T) -> T { *self + *other }
181182
}
182183
#[cfg(notest)]
183184
impl ops::Sub<T,T> for T {
185+
#[inline(always)]
184186
fn sub(&self, other: &T) -> T { *self - *other }
185187
}
186188
#[cfg(notest)]
187189
impl ops::Mul<T,T> for T {
190+
#[inline(always)]
188191
fn mul(&self, other: &T) -> T { *self * *other }
189192
}
190193
#[cfg(notest)]
191194
impl ops::Div<T,T> for T {
195+
#[inline(always)]
192196
fn div(&self, other: &T) -> T { *self / *other }
193197
}
194198
#[cfg(notest)]
195199
impl ops::Modulo<T,T> for T {
200+
#[inline(always)]
196201
fn modulo(&self, other: &T) -> T { *self % *other }
197202
}
198203
#[cfg(notest)]
199204
impl ops::Neg<T> for T {
205+
#[inline(always)]
200206
fn neg(&self) -> T { -*self }
201207
}
208+
202209
#[cfg(notest)]
203210
impl ops::BitOr<T,T> for T {
211+
#[inline(always)]
204212
fn bitor(&self, other: &T) -> T { *self | *other }
205213
}
206214
#[cfg(notest)]
207215
impl ops::BitAnd<T,T> for T {
216+
#[inline(always)]
208217
fn bitand(&self, other: &T) -> T { *self & *other }
209218
}
210219
#[cfg(notest)]
211220
impl ops::BitXor<T,T> for T {
221+
#[inline(always)]
212222
fn bitxor(&self, other: &T) -> T { *self ^ *other }
213223
}
214224
#[cfg(notest)]
215225
impl ops::Shl<T,T> for T {
226+
#[inline(always)]
216227
fn shl(&self, other: &T) -> T { *self << *other }
217228
}
218229
#[cfg(notest)]
219230
impl ops::Shr<T,T> for T {
231+
#[inline(always)]
220232
fn shr(&self, other: &T) -> T { *self >> *other }
221233
}
222234
#[cfg(notest)]
223235
impl ops::Not<T> for T {
236+
#[inline(always)]
224237
fn not(&self) -> T { !*self }
225238
}
226239

src/libcore/num/uint-template.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,50 +142,63 @@ impl num::One for T {
142142
143143
#[cfg(notest)]
144144
impl ops::Add<T,T> for T {
145+
#[inline(always)]
145146
fn add(&self, other: &T) -> T { *self + *other }
146147
}
147148
#[cfg(notest)]
148149
impl ops::Sub<T,T> for T {
150+
#[inline(always)]
149151
fn sub(&self, other: &T) -> T { *self - *other }
150152
}
151153
#[cfg(notest)]
152154
impl ops::Mul<T,T> for T {
155+
#[inline(always)]
153156
fn mul(&self, other: &T) -> T { *self * *other }
154157
}
155158
#[cfg(notest)]
156159
impl ops::Div<T,T> for T {
160+
#[inline(always)]
157161
fn div(&self, other: &T) -> T { *self / *other }
158162
}
159163
#[cfg(notest)]
160164
impl ops::Modulo<T,T> for T {
165+
#[inline(always)]
161166
fn modulo(&self, other: &T) -> T { *self % *other }
162167
}
163168
#[cfg(notest)]
164169
impl ops::Neg<T> for T {
170+
#[inline(always)]
165171
fn neg(&self) -> T { -*self }
166172
}
173+
167174
#[cfg(notest)]
168175
impl ops::BitOr<T,T> for T {
176+
#[inline(always)]
169177
fn bitor(&self, other: &T) -> T { *self | *other }
170178
}
171179
#[cfg(notest)]
172180
impl ops::BitAnd<T,T> for T {
181+
#[inline(always)]
173182
fn bitand(&self, other: &T) -> T { *self & *other }
174183
}
175184
#[cfg(notest)]
176185
impl ops::BitXor<T,T> for T {
186+
#[inline(always)]
177187
fn bitxor(&self, other: &T) -> T { *self ^ *other }
178188
}
179189
#[cfg(notest)]
180190
impl ops::Shl<T,T> for T {
191+
#[inline(always)]
181192
fn shl(&self, other: &T) -> T { *self << *other }
182193
}
183194
#[cfg(notest)]
184195
impl ops::Shr<T,T> for T {
196+
#[inline(always)]
185197
fn shr(&self, other: &T) -> T { *self >> *other }
186198
}
187199
#[cfg(notest)]
188200
impl ops::Not<T> for T {
201+
#[inline(always)]
189202
fn not(&self) -> T { !*self }
190203
}
191204

0 commit comments

Comments
 (0)