summaryrefslogtreecommitdiffstats
path: root/src/xcursor.rs
diff options
context:
space:
mode:
authorLibravatarLarge Libravatar memdmp <memdmpestrogenzone>2026-01-25 16:31:33 +0100
committerLibravatarLarge Libravatar memdmp <memdmpestrogenzone>2026-01-25 16:31:33 +0100
commit6ae2681aa1abc1fa447d64d2a269878e29b1d904 (patch)
treec2069ee898a2d30c8eab1ddde36691653d6abb93 /src/xcursor.rs
parent6e3b3c8013e6d8814dbf70c854e55d062bedbdf4 (diff)
downloadbibata-cursor-cli-6ae2681aa1abc1fa447d64d2a269878e29b1d904.tar.gz
bibata-cursor-cli-6ae2681aa1abc1fa447d64d2a269878e29b1d904.tar.bz2
bibata-cursor-cli-6ae2681aa1abc1fa447d64d2a269878e29b1d904.tar.lz
bibata-cursor-cli-6ae2681aa1abc1fa447d64d2a269878e29b1d904.zip

feat: paralllelism, memory overcommitment to save on repeated mallocs

Diffstat (limited to 'src/xcursor.rs')
-rw-r--r--src/xcursor.rs23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/xcursor.rs b/src/xcursor.rs
index ff6c3d6..8d329bf 100644
--- a/src/xcursor.rs
+++ b/src/xcursor.rs
@@ -31,11 +31,14 @@ impl XCursorEncoder {
}
pub fn pack(&mut self) -> Vec<u8> {
- fn insert_bytes(data: &mut Vec<u8>, new_data: impl IntoIterator<Item = u8>) {
- for int in new_data {
- data.push(int);
- }
+ fn insert_bytes(data: &mut Vec<u8>, new_data: &[u8]) {
+ data.extend_from_slice(new_data);
}
+ // fn insert_iterated(data: &mut Vec<u8>, new_data: impl IntoIterator<Item = u8>) {
+ // for int in new_data {
+ // data.push(int);
+ // }
+ // }
fn insert_int(data: &mut Vec<u8>, int: u32) {
data.push((int & 0xff) as u8);
data.push(((int >> 8) & 0xff) as u8);
@@ -44,11 +47,15 @@ impl XCursorEncoder {
}
let mut data: Vec<u8> = Vec::new();
+ #[cfg(feature="overalloc")]
+ data.reserve(
+ 4194304
+ );
// File Header
{
// MAGIC string ("Xcur")
- insert_bytes(&mut data, MAGIC);
+ insert_bytes(&mut data, &MAGIC);
// CARD32 bytes in this header
insert_int(&mut data, 16);
// CARD32 file version
@@ -62,7 +69,7 @@ impl XCursorEncoder {
let mut img_idx: usize = 0;
for img in self.images.clone().into_iter() {
// Some header
- insert_bytes(&mut data, IMAGE_HEADER);
+ insert_bytes(&mut data, &IMAGE_HEADER);
// CARD32 type-specific label - size for images
insert_int(&mut data, img.r#type);
// CARD32 absolute byte position of table in file
@@ -78,7 +85,7 @@ impl XCursorEncoder {
// Header Size (36)
insert_int(&mut data, 36);
// Image Type
- insert_bytes(&mut data, IMAGE_HEADER);
+ insert_bytes(&mut data, &IMAGE_HEADER);
// Subtype, for nominal size
insert_int(&mut data, img.subtype);
// Version
@@ -92,7 +99,7 @@ impl XCursorEncoder {
// Milliseconds till next frame
insert_int(&mut data, img.delay);
// Raw image data
- insert_bytes(&mut data, img.data);
+ insert_bytes(&mut data, &img.data);
}
}