summaryrefslogtreecommitdiff
path: root/helix-view/src/lib.rs
diff options
context:
space:
mode:
authorIvan Tham2021-11-25 02:07:23 +0000
committerGitHub2021-11-25 02:07:23 +0000
commit67bf4250caf14d3a632abdbfa367c04b318d782c (patch)
tree23a012baabf11214c7b235ca7a9ab8ee777b9f3e /helix-view/src/lib.rs
parente8f800a141af11b4f2f4c838cd4fd1f8aa7fa971 (diff)
Optimize space for DocumentId with NonZeroUsize (#1097)
Now Option<DocumentId> uses one byte rather than two
Diffstat (limited to 'helix-view/src/lib.rs')
-rw-r--r--helix-view/src/lib.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/helix-view/src/lib.rs b/helix-view/src/lib.rs
index 3e779356..4d19ee2e 100644
--- a/helix-view/src/lib.rs
+++ b/helix-view/src/lib.rs
@@ -12,8 +12,18 @@ pub mod theme;
pub mod tree;
pub mod view;
-#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)]
-pub struct DocumentId(usize);
+use std::num::NonZeroUsize;
+
+// uses NonZeroUsize so Option<DocumentId> use a byte rather than two
+#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
+pub struct DocumentId(NonZeroUsize);
+
+impl Default for DocumentId {
+ fn default() -> DocumentId {
+ // Safety: 1 is non-zero
+ DocumentId(unsafe { NonZeroUsize::new_unchecked(1) })
+ }
+}
slotmap::new_key_type! {
pub struct ViewId;