Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace once_cell Lazy with ordinary static #1447

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ hyper-timeout = "0.5.1"
json-patch = "1.0.0"
jsonpath-rust = "0.5.0"
k8s-openapi = { version = "0.21.0", default-features = false }
once_cell = "1.8.0"
openssl = "0.10.36"
parking_lot = "0.12.0"
pem = "3.0.1"
Expand Down
1 change: 0 additions & 1 deletion kube-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ thiserror.workspace = true
form_urlencoded.workspace = true
http.workspace = true
json-patch = { workspace = true, optional = true }
once_cell.workspace = true
chrono = { workspace = true, features = ["clock"] }
schemars = { workspace = true, optional = true }
k8s-openapi.workspace = true
Expand Down
9 changes: 3 additions & 6 deletions kube-core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,7 @@ pub trait ResourceExt: Resource {
fn managed_fields_mut(&mut self) -> &mut Vec<ManagedFieldsEntry>;
}

// TODO: replace with ordinary static when BTreeMap::new() is no longer
// const-unstable.
use once_cell::sync::Lazy;
static EMPTY_MAP: Lazy<BTreeMap<String, String>> = Lazy::new(BTreeMap::new);
static EMPTY_MAP: BTreeMap<String, String> = BTreeMap::new();

impl<K: Resource> ResourceExt for K {
fn name_unchecked(&self) -> String {
Expand Down Expand Up @@ -251,15 +248,15 @@ impl<K: Resource> ResourceExt for K {
}

fn labels(&self) -> &BTreeMap<String, String> {
self.meta().labels.as_ref().unwrap_or(&*EMPTY_MAP)
self.meta().labels.as_ref().unwrap_or(&EMPTY_MAP)
}

fn labels_mut(&mut self) -> &mut BTreeMap<String, String> {
self.meta_mut().labels.get_or_insert_with(BTreeMap::new)
}

fn annotations(&self) -> &BTreeMap<String, String> {
self.meta().annotations.as_ref().unwrap_or(&*EMPTY_MAP)
self.meta().annotations.as_ref().unwrap_or(&EMPTY_MAP)
}

fn annotations_mut(&mut self) -> &mut BTreeMap<String, String> {
Expand Down
Loading