Skip to content

Commit 21bb0dc

Browse files
committed
Run rustfmt on libarena.
1 parent 81b3b27 commit 21bb0dc

File tree

1 file changed

+50
-70
lines changed

1 file changed

+50
-70
lines changed

src/libarena/lib.rs

+50-70
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub struct Arena<'longer_than_self> {
105105
head: RefCell<Chunk>,
106106
copy_head: RefCell<Chunk>,
107107
chunks: RefCell<Vec<Chunk>>,
108-
_marker: marker::PhantomData<*mut &'longer_than_self()>,
108+
_marker: marker::PhantomData<*mut &'longer_than_self ()>,
109109
}
110110

111111
impl<'a> Arena<'a> {
@@ -197,7 +197,7 @@ fn un_bitpack_tydesc_ptr(p: usize) -> (*const TyDesc, bool) {
197197
struct TyDesc {
198198
drop_glue: fn(*const i8),
199199
size: usize,
200-
align: usize
200+
align: usize,
201201
}
202202

203203
trait AllTypes { fn dummy(&self) { } }
@@ -224,8 +224,7 @@ impl<'longer_than_self> Arena<'longer_than_self> {
224224
let new_min_chunk_size = cmp::max(n_bytes, self.chunk_size());
225225
self.chunks.borrow_mut().push(self.copy_head.borrow().clone());
226226

227-
*self.copy_head.borrow_mut() =
228-
chunk((new_min_chunk_size + 1).next_power_of_two(), true);
227+
*self.copy_head.borrow_mut() = chunk((new_min_chunk_size + 1).next_power_of_two(), true);
229228

230229
self.alloc_copy_inner(n_bytes, align)
231230
}
@@ -242,38 +241,32 @@ impl<'longer_than_self> Arena<'longer_than_self> {
242241
let copy_head = self.copy_head.borrow();
243242
copy_head.fill.set(end);
244243

245-
unsafe {
246-
copy_head.as_ptr().offset(start as isize)
247-
}
244+
unsafe { copy_head.as_ptr().offset(start as isize) }
248245
}
249246

250247
#[inline]
251248
fn alloc_copy<T, F>(&self, op: F) -> &mut T where F: FnOnce() -> T {
252249
unsafe {
253-
let ptr = self.alloc_copy_inner(mem::size_of::<T>(),
254-
mem::align_of::<T>());
250+
let ptr = self.alloc_copy_inner(mem::size_of::<T>(), mem::align_of::<T>());
255251
let ptr = ptr as *mut T;
256252
ptr::write(&mut (*ptr), op());
257253
&mut *ptr
258254
}
259255
}
260256

261257
// Functions for the non-POD part of the arena
262-
fn alloc_noncopy_grow(&self, n_bytes: usize,
263-
align: usize) -> (*const u8, *const u8) {
258+
fn alloc_noncopy_grow(&self, n_bytes: usize, align: usize) -> (*const u8, *const u8) {
264259
// Allocate a new chunk.
265260
let new_min_chunk_size = cmp::max(n_bytes, self.chunk_size());
266261
self.chunks.borrow_mut().push(self.head.borrow().clone());
267262

268-
*self.head.borrow_mut() =
269-
chunk((new_min_chunk_size + 1).next_power_of_two(), false);
263+
*self.head.borrow_mut() = chunk((new_min_chunk_size + 1).next_power_of_two(), false);
270264

271265
self.alloc_noncopy_inner(n_bytes, align)
272266
}
273267

274268
#[inline]
275-
fn alloc_noncopy_inner(&self, n_bytes: usize,
276-
align: usize) -> (*const u8, *const u8) {
269+
fn alloc_noncopy_inner(&self, n_bytes: usize, align: usize) -> (*const u8, *const u8) {
277270
// Be careful to not maintain any `head` borrows active, because
278271
// `alloc_noncopy_grow` borrows it mutably.
279272
let (start, end, tydesc_start, head_capacity) = {
@@ -297,24 +290,23 @@ impl<'longer_than_self> Arena<'longer_than_self> {
297290

298291
unsafe {
299292
let buf = head.as_ptr();
300-
(buf.offset(tydesc_start as isize), buf.offset(start as isize))
293+
(buf.offset(tydesc_start as isize),
294+
buf.offset(start as isize))
301295
}
302296
}
303297

304298
#[inline]
305299
fn alloc_noncopy<T, F>(&self, op: F) -> &mut T where F: FnOnce() -> T {
306300
unsafe {
307301
let tydesc = get_tydesc::<T>();
308-
let (ty_ptr, ptr) =
309-
self.alloc_noncopy_inner(mem::size_of::<T>(),
310-
mem::align_of::<T>());
302+
let (ty_ptr, ptr) = self.alloc_noncopy_inner(mem::size_of::<T>(), mem::align_of::<T>());
311303
let ty_ptr = ty_ptr as *mut usize;
312304
let ptr = ptr as *mut T;
313305
// Write in our tydesc along with a bit indicating that it
314306
// has *not* been initialized yet.
315307
*ty_ptr = bitpack_tydesc_ptr(tydesc, false);
316308
// Actually initialize it
317-
ptr::write(&mut(*ptr), op());
309+
ptr::write(&mut (*ptr), op());
318310
// Now that we are done, update the tydesc to indicate that
319311
// the object is there.
320312
*ty_ptr = bitpack_tydesc_ptr(tydesc, true);
@@ -358,10 +350,10 @@ fn test_arena_destructors_fail() {
358350
for i in 0..10 {
359351
// Arena allocate something with drop glue to make sure it
360352
// doesn't leak.
361-
arena.alloc(|| { Rc::new(i) });
353+
arena.alloc(|| Rc::new(i));
362354
// Allocate something with funny size and alignment, to keep
363355
// things interesting.
364-
arena.alloc(|| { [0u8, 1, 2] });
356+
arena.alloc(|| [0u8, 1, 2]);
365357
}
366358
// Now, panic while allocating
367359
arena.alloc::<Rc<i32>, _>(|| {
@@ -409,12 +401,13 @@ fn calculate_size<T>(capacity: usize) -> usize {
409401

410402
impl<T> TypedArenaChunk<T> {
411403
#[inline]
412-
unsafe fn new(next: *mut TypedArenaChunk<T>, capacity: usize)
413-
-> *mut TypedArenaChunk<T> {
404+
unsafe fn new(next: *mut TypedArenaChunk<T>, capacity: usize) -> *mut TypedArenaChunk<T> {
414405
let size = calculate_size::<T>(capacity);
415-
let chunk = allocate(size, mem::align_of::<TypedArenaChunk<T>>())
416-
as *mut TypedArenaChunk<T>;
417-
if chunk.is_null() { alloc::oom() }
406+
let chunk =
407+
allocate(size, mem::align_of::<TypedArenaChunk<T>>()) as *mut TypedArenaChunk<T>;
408+
if chunk.is_null() {
409+
alloc::oom()
410+
}
418411
(*chunk).next = next;
419412
(*chunk).capacity = capacity;
420413
chunk
@@ -437,7 +430,8 @@ impl<T> TypedArenaChunk<T> {
437430
let next = self.next;
438431
let size = calculate_size::<T>(self.capacity);
439432
let self_ptr: *mut TypedArenaChunk<T> = self;
440-
deallocate(self_ptr as *mut u8, size,
433+
deallocate(self_ptr as *mut u8,
434+
size,
441435
mem::align_of::<TypedArenaChunk<T>>());
442436
if !next.is_null() {
443437
let capacity = (*next).capacity;
@@ -449,9 +443,7 @@ impl<T> TypedArenaChunk<T> {
449443
#[inline]
450444
fn start(&self) -> *const u8 {
451445
let this: *const TypedArenaChunk<T> = self;
452-
unsafe {
453-
round_up(this.offset(1) as usize, mem::align_of::<T>()) as *const u8
454-
}
446+
unsafe { round_up(this.offset(1) as usize, mem::align_of::<T>()) as *const u8 }
455447
}
456448

457449
// Returns a pointer to the end of the allocated space.
@@ -545,22 +537,29 @@ mod tests {
545537

546538
#[test]
547539
fn test_arena_alloc_nested() {
548-
struct Inner { value: u8 }
549-
struct Outer<'a> { inner: &'a Inner }
550-
enum EI<'e> { I(Inner), O(Outer<'e>) }
540+
struct Inner {
541+
value: u8,
542+
}
543+
struct Outer<'a> {
544+
inner: &'a Inner,
545+
}
546+
enum EI<'e> {
547+
I(Inner),
548+
O(Outer<'e>),
549+
}
551550

552551
struct Wrap<'a>(TypedArena<EI<'a>>);
553552

554553
impl<'a> Wrap<'a> {
555-
fn alloc_inner<F:Fn() -> Inner>(&self, f: F) -> &Inner {
554+
fn alloc_inner<F: Fn() -> Inner>(&self, f: F) -> &Inner {
556555
let r: &EI = self.0.alloc(EI::I(f()));
557556
if let &EI::I(ref i) = r {
558557
i
559558
} else {
560559
panic!("mismatch");
561560
}
562561
}
563-
fn alloc_outer<F:Fn() -> Outer<'a>>(&self, f: F) -> &Outer {
562+
fn alloc_outer<F: Fn() -> Outer<'a>>(&self, f: F) -> &Outer {
564563
let r: &EI = self.0.alloc(EI::O(f()));
565564
if let &EI::O(ref o) = r {
566565
o
@@ -572,8 +571,9 @@ mod tests {
572571

573572
let arena = Wrap(TypedArena::new());
574573

575-
let result = arena.alloc_outer(|| Outer {
576-
inner: arena.alloc_inner(|| Inner { value: 10 }) });
574+
let result = arena.alloc_outer(|| {
575+
Outer { inner: arena.alloc_inner(|| Inner { value: 10 }) }
576+
});
577577

578578
assert_eq!(result.inner.value, 10);
579579
}
@@ -582,49 +582,27 @@ mod tests {
582582
pub fn test_copy() {
583583
let arena = TypedArena::new();
584584
for _ in 0..100000 {
585-
arena.alloc(Point {
586-
x: 1,
587-
y: 2,
588-
z: 3,
589-
});
585+
arena.alloc(Point { x: 1, y: 2, z: 3 });
590586
}
591587
}
592588

593589
#[bench]
594590
pub fn bench_copy(b: &mut Bencher) {
595591
let arena = TypedArena::new();
596-
b.iter(|| {
597-
arena.alloc(Point {
598-
x: 1,
599-
y: 2,
600-
z: 3,
601-
})
602-
})
592+
b.iter(|| arena.alloc(Point { x: 1, y: 2, z: 3 }))
603593
}
604594

605595
#[bench]
606596
pub fn bench_copy_nonarena(b: &mut Bencher) {
607597
b.iter(|| {
608-
let _: Box<_> = box Point {
609-
x: 1,
610-
y: 2,
611-
z: 3,
612-
};
598+
let _: Box<_> = box Point { x: 1, y: 2, z: 3 };
613599
})
614600
}
615601

616602
#[bench]
617603
pub fn bench_copy_old_arena(b: &mut Bencher) {
618604
let arena = Arena::new();
619-
b.iter(|| {
620-
arena.alloc(|| {
621-
Point {
622-
x: 1,
623-
y: 2,
624-
z: 3,
625-
}
626-
})
627-
})
605+
b.iter(|| arena.alloc(|| Point { x: 1, y: 2, z: 3 }))
628606
}
629607

630608
#[allow(dead_code)]
@@ -639,7 +617,7 @@ mod tests {
639617
for _ in 0..100000 {
640618
arena.alloc(Noncopy {
641619
string: "hello world".to_string(),
642-
array: vec!( 1, 2, 3, 4, 5 ),
620+
array: vec!(1, 2, 3, 4, 5),
643621
});
644622
}
645623
}
@@ -650,7 +628,7 @@ mod tests {
650628
b.iter(|| {
651629
arena.alloc(Noncopy {
652630
string: "hello world".to_string(),
653-
array: vec!( 1, 2, 3, 4, 5 ),
631+
array: vec!(1, 2, 3, 4, 5),
654632
})
655633
})
656634
}
@@ -660,7 +638,7 @@ mod tests {
660638
b.iter(|| {
661639
let _: Box<_> = box Noncopy {
662640
string: "hello world".to_string(),
663-
array: vec!( 1, 2, 3, 4, 5 ),
641+
array: vec!(1, 2, 3, 4, 5),
664642
};
665643
})
666644
}
@@ -669,9 +647,11 @@ mod tests {
669647
pub fn bench_noncopy_old_arena(b: &mut Bencher) {
670648
let arena = Arena::new();
671649
b.iter(|| {
672-
arena.alloc(|| Noncopy {
673-
string: "hello world".to_string(),
674-
array: vec!( 1, 2, 3, 4, 5 ),
650+
arena.alloc(|| {
651+
Noncopy {
652+
string: "hello world".to_string(),
653+
array: vec!(1, 2, 3, 4, 5),
654+
}
675655
})
676656
})
677657
}

0 commit comments

Comments
 (0)