Skip to content

Commit

Permalink
Remove direct once_cell dependency
Browse files Browse the repository at this point in the history
The class! macro performs the same static caching and is cheaper than once_cell::Lazy
  • Loading branch information
complexspaces committed Aug 29, 2023
1 parent 7af9a37 commit 7b5ff1d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 9 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2018"

[features]
default = ["image-data"]
image-data = ["core-graphics", "once_cell", "image", "winapi/minwindef", "winapi/wingdi", "winapi/winnt"]
image-data = ["core-graphics", "image", "winapi/minwindef", "winapi/wingdi", "winapi/winnt"]
wayland-data-control = ["wl-clipboard-rs"]

[dependencies]
Expand All @@ -34,7 +34,6 @@ log = "0.4"
objc = "0.2"
objc_id = "0.1"
objc-foundation = "0.1"
once_cell = { version = "1", optional = true }
core-graphics = { version = "0.22", optional = true }
image = { version = "0.24", optional = true, default-features = false, features = ["tiff"] }

Expand Down
8 changes: 2 additions & 6 deletions src/platform/osx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ use objc::{
};
use objc_foundation::{INSArray, INSFastEnumeration, INSString, NSArray, NSObject, NSString};
use objc_id::{Id, Owned};
#[cfg(feature = "image-data")]
use once_cell::sync::Lazy;
use std::{borrow::Cow, ptr::NonNull};

// Required to bring NSPasteboard into the path of the class-resolver
Expand All @@ -39,9 +37,6 @@ extern "C" {
static NSPasteboardTypeTIFF: *const Object;
}

#[cfg(feature = "image-data")]
static NSIMAGE_CLASS: Lazy<&Class> = Lazy::new(|| Class::get("NSImage").unwrap());

/// Returns an NSImage object on success.
#[cfg(feature = "image-data")]
fn image_from_pixels(
Expand Down Expand Up @@ -87,8 +82,9 @@ fn image_from_pixels(
kCGRenderingIntentDefault,
);
let size = NSSize { width: width as CGFloat, height: height as CGFloat };
let nsimage_class = objc::class!(NSImage);
// Take ownership of the newly allocated object, which has an existing retain count.
let image: Id<NSObject> = unsafe { Id::from_retained_ptr(msg_send![*NSIMAGE_CLASS, alloc]) };
let image: Id<NSObject> = unsafe { Id::from_retained_ptr(msg_send![nsimage_class, alloc]) };
#[allow(clippy::let_unit_value)]
{
// Note: `initWithCGImage` expects a reference (`CGImageRef`), not an actual object.
Expand Down

0 comments on commit 7b5ff1d

Please sign in to comment.