Skip to content

Truly independent web browser

LibWeb: Drop collected PermissionStatuses when registering another

Shannon Booth78a4569ed7d8
diff --git a/Libraries/LibWeb/Bindings/Rust/src/permissions_api/permission_store.rs b/Libraries/LibWeb/Bindings/Rust/src/permissions_api/permission_store.rs
index 4cef05cda74..d47daae2960 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/permissions_api/permission_store.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/permissions_api/permission_store.rs
@@ -23,7 +23,15 @@ thread_local! {
}
pub(crate) fn register_status(vm: &Vm, status: Ref<PermissionStatus>) {
- PERMISSION_STATUSES.with_borrow_mut(|statuses| statuses.push(GcWeak::new(vm.heap(), status)));
+ PERMISSION_STATUSES.with_borrow_mut(|statuses| {
+ // Pruning only when the vector would grow, and leaving it at most half full, keeps a registration amortized
+ // constant time.
+ if statuses.len() == statuses.capacity() {
+ statuses.retain(|status| status.get().is_some());
+ statuses.reserve(statuses.len());
+ }
+ statuses.push(GcWeak::new(vm.heap(), status));
+ });
}
/// Reads the state of every status of the thread's agent again from the permission store, once the store has applied