Remove a few unnecessary usages of Lazy (#3531)
* Convert usage of Lazy to OnceLock on macOS and iOS * Remove a few uses of Lazy that wrapped Mutex or RwLock The `new` functions on these were made `const` in Rust 1.63.0 * Use AtomicBool instead of RwLock
This commit is contained in:
parent
a5dbd3ee52
commit
c4e6e94b80
6 changed files with 51 additions and 52 deletions
|
|
@ -1,4 +1,7 @@
|
|||
use crate::utils::Lazy;
|
||||
use std::ffi::c_uchar;
|
||||
use std::slice;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use icrate::AppKit::{NSBitmapImageRep, NSCursor, NSDeviceRGBColorSpace, NSImage};
|
||||
use icrate::Foundation::{
|
||||
ns_string, NSData, NSDictionary, NSNumber, NSObject, NSObjectProtocol, NSPoint, NSSize,
|
||||
|
|
@ -7,8 +10,6 @@ use icrate::Foundation::{
|
|||
use objc2::rc::Id;
|
||||
use objc2::runtime::Sel;
|
||||
use objc2::{msg_send_id, sel, ClassType};
|
||||
use std::ffi::c_uchar;
|
||||
use std::slice;
|
||||
|
||||
use crate::cursor::CursorImage;
|
||||
use crate::cursor::OnlyCursorImageSource;
|
||||
|
|
@ -171,19 +172,20 @@ pub(crate) fn invisible_cursor() -> Id<NSCursor> {
|
|||
0xA3, 0x9C, 0xB4, 0xDA, 0x8B, 0xB3, 0x3E, 0x05, 0x00, 0x3B,
|
||||
];
|
||||
|
||||
static CURSOR: Lazy<CustomCursor> = Lazy::new(|| {
|
||||
fn new_invisible() -> Id<NSCursor> {
|
||||
// TODO: Consider using `dataWithBytesNoCopy:`
|
||||
let data = NSData::with_bytes(CURSOR_BYTES);
|
||||
let image = NSImage::initWithData(NSImage::alloc(), &data).unwrap();
|
||||
let hotspot = NSPoint::new(0.0, 0.0);
|
||||
CustomCursor(NSCursor::initWithImage_hotSpot(
|
||||
NSCursor::alloc(),
|
||||
&image,
|
||||
hotspot,
|
||||
))
|
||||
});
|
||||
NSCursor::initWithImage_hotSpot(NSCursor::alloc(), &image, hotspot)
|
||||
}
|
||||
|
||||
CURSOR.0.clone()
|
||||
// Cache this for efficiency
|
||||
static CURSOR: OnceLock<CustomCursor> = OnceLock::new();
|
||||
CURSOR
|
||||
.get_or_init(|| CustomCursor(new_invisible()))
|
||||
.0
|
||||
.clone()
|
||||
}
|
||||
|
||||
pub(crate) fn cursor_from_icon(icon: CursorIcon) -> Id<NSCursor> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue