about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2020-10-20 21:46:40 +0200
committerGitHub <noreply@github.com>2020-10-20 21:46:40 +0200
commitad218f9bb92cbeb9bf21c319d7a04eb47cfdb56e (patch)
tree4b6316897ba0a9f989ad4207ff2117087dad70be
parenta8a424f4aad4444a89f1d40d97ef9da824f7d015 (diff)
parent2705caed8afbf41e1d0ae5e88a70a92687a1a5da (diff)
downloadrust-ad218f9bb92cbeb9bf21c319d7a04eb47cfdb56e.tar.gz
rust-ad218f9bb92cbeb9bf21c319d7a04eb47cfdb56e.zip
Rollup merge of #78144 - bugadani:elements-nodrop, r=oli-obk
Don't update `entries` in `TypedArena` if T does not need drop

As far as I can tell, `entries` is only used when dropping `TypedArenaChunk`s and their contents. It is already ignored there, if T is not `mem::needs_drop`, this PR just skips updating it's value.

You can see `TypedArenaChunk` ignoring the entry count in L71. The reasoning is similar to what you can find in `DroplessArena`.

r? @oli-obk
-rw-r--r--compiler/rustc_arena/src/lib.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/compiler/rustc_arena/src/lib.rs b/compiler/rustc_arena/src/lib.rs
index 34736b820e9..1a85a46ed74 100644
--- a/compiler/rustc_arena/src/lib.rs
+++ b/compiler/rustc_arena/src/lib.rs
@@ -217,8 +217,12 @@ impl<T> TypedArena<T> {
             let mut chunks = self.chunks.borrow_mut();
             let mut new_cap;
             if let Some(last_chunk) = chunks.last_mut() {
-                let used_bytes = self.ptr.get() as usize - last_chunk.start() as usize;
-                last_chunk.entries = used_bytes / mem::size_of::<T>();
+                // If a type is `!needs_drop`, we don't need to keep track of how many elements
+                // the chunk stores - the field will be ignored anyway.
+                if mem::needs_drop::<T>() {
+                    let used_bytes = self.ptr.get() as usize - last_chunk.start() as usize;
+                    last_chunk.entries = used_bytes / mem::size_of::<T>();
+                }
 
                 // If the previous chunk's len is less than HUGE_PAGE
                 // bytes, then this chunk will be least double the previous