Skip to content

Commit

Permalink
Merge pull request #1447 from tottoto/once-cell
Browse files Browse the repository at this point in the history
replace once_cell Lazy with ordinary static
  • Loading branch information
nightkr authored Mar 27, 2024
2 parents a868bbf + 4848d45 commit 0952c2a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
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

0 comments on commit 0952c2a

Please sign in to comment.