@@ -229,11 +229,13 @@ pub struct Size {
229
229
impl Size {
230
230
pub const ZERO : Size = Self :: from_bytes ( 0 ) ;
231
231
232
+ #[ inline]
232
233
pub fn from_bits ( bits : u64 ) -> Size {
233
234
// Avoid potential overflow from `bits + 7`.
234
235
Size :: from_bytes ( bits / 8 + ( ( bits % 8 ) + 7 ) / 8 )
235
236
}
236
237
238
+ #[ inline]
237
239
pub const fn from_bytes ( bytes : u64 ) -> Size {
238
240
Size {
239
241
raw : bytes
@@ -245,22 +247,26 @@ impl Size {
245
247
self . raw
246
248
}
247
249
250
+ #[ inline]
248
251
pub fn bits ( self ) -> u64 {
249
252
self . bytes ( ) . checked_mul ( 8 ) . unwrap_or_else ( || {
250
253
panic ! ( "Size::bits: {} bytes in bits doesn't fit in u64" , self . bytes( ) )
251
254
} )
252
255
}
253
256
257
+ #[ inline]
254
258
pub fn abi_align ( self , align : Align ) -> Size {
255
259
let mask = align. abi ( ) - 1 ;
256
260
Size :: from_bytes ( ( self . bytes ( ) + mask) & !mask)
257
261
}
258
262
263
+ #[ inline]
259
264
pub fn is_abi_aligned ( self , align : Align ) -> bool {
260
265
let mask = align. abi ( ) - 1 ;
261
266
self . bytes ( ) & mask == 0
262
267
}
263
268
269
+ #[ inline]
264
270
pub fn checked_add < C : HasDataLayout > ( self , offset : Size , cx : C ) -> Option < Size > {
265
271
let dl = cx. data_layout ( ) ;
266
272
@@ -273,6 +279,7 @@ impl Size {
273
279
}
274
280
}
275
281
282
+ #[ inline]
276
283
pub fn checked_mul < C : HasDataLayout > ( self , count : u64 , cx : C ) -> Option < Size > {
277
284
let dl = cx. data_layout ( ) ;
278
285
@@ -290,6 +297,7 @@ impl Size {
290
297
291
298
impl Add for Size {
292
299
type Output = Size ;
300
+ #[ inline]
293
301
fn add ( self , other : Size ) -> Size {
294
302
Size :: from_bytes ( self . bytes ( ) . checked_add ( other. bytes ( ) ) . unwrap_or_else ( || {
295
303
panic ! ( "Size::add: {} + {} doesn't fit in u64" , self . bytes( ) , other. bytes( ) )
@@ -299,6 +307,7 @@ impl Add for Size {
299
307
300
308
impl Sub for Size {
301
309
type Output = Size ;
310
+ #[ inline]
302
311
fn sub ( self , other : Size ) -> Size {
303
312
Size :: from_bytes ( self . bytes ( ) . checked_sub ( other. bytes ( ) ) . unwrap_or_else ( || {
304
313
panic ! ( "Size::sub: {} - {} would result in negative size" , self . bytes( ) , other. bytes( ) )
@@ -308,13 +317,15 @@ impl Sub for Size {
308
317
309
318
impl Mul < Size > for u64 {
310
319
type Output = Size ;
320
+ #[ inline]
311
321
fn mul ( self , size : Size ) -> Size {
312
322
size * self
313
323
}
314
324
}
315
325
316
326
impl Mul < u64 > for Size {
317
327
type Output = Size ;
328
+ #[ inline]
318
329
fn mul ( self , count : u64 ) -> Size {
319
330
match self . bytes ( ) . checked_mul ( count) {
320
331
Some ( bytes) => Size :: from_bytes ( bytes) ,
@@ -326,6 +337,7 @@ impl Mul<u64> for Size {
326
337
}
327
338
328
339
impl AddAssign for Size {
340
+ #[ inline]
329
341
fn add_assign ( & mut self , other : Size ) {
330
342
* self = * self + other;
331
343
}
0 commit comments