Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

gpui: Simplify u8 to u32 conversion (#32099)

tidely738cfdff84e6
diff --git a/crates/gpui/src/platform/windows/direct_write.rs b/crates/gpui/src/platform/windows/direct_write.rs
index 6dbc1f5c04d..a0615404f33 100644
--- a/crates/gpui/src/platform/windows/direct_write.rs
+++ b/crates/gpui/src/platform/windows/direct_write.rs
@@ -1351,7 +1351,7 @@ fn apply_font_features(
}
#[inline]
-fn make_direct_write_feature(feature_name: &str, parameter: u32) -> DWRITE_FONT_FEATURE {
+const fn make_direct_write_feature(feature_name: &str, parameter: u32) -> DWRITE_FONT_FEATURE {
let tag = make_direct_write_tag(feature_name);
DWRITE_FONT_FEATURE {
nameTag: tag,
@@ -1360,17 +1360,14 @@ fn make_direct_write_feature(feature_name: &str, parameter: u32) -> DWRITE_FONT_
}
#[inline]
-fn make_open_type_tag(tag_name: &str) -> u32 {
- let bytes = tag_name.bytes().collect_vec();
- assert_eq!(bytes.len(), 4);
- ((bytes[3] as u32) << 24)
- | ((bytes[2] as u32) << 16)
- | ((bytes[1] as u32) << 8)
- | (bytes[0] as u32)
+const fn make_open_type_tag(tag_name: &str) -> u32 {
+ let bytes = tag_name.as_bytes();
+ debug_assert!(bytes.len() == 4);
+ u32::from_le_bytes([bytes[0], bytes[1], bytes[2], bytes[3]])
}
#[inline]
-fn make_direct_write_tag(tag_name: &str) -> DWRITE_FONT_FEATURE_TAG {
+const fn make_direct_write_tag(tag_name: &str) -> DWRITE_FONT_FEATURE_TAG {
DWRITE_FONT_FEATURE_TAG(make_open_type_tag(tag_name))
}