gpui: Simplify u8 to u32 conversion (#32099)

Removes an allocation when converting four u8 into a u32.
Makes some functions const compatible.

Release Notes:

- N/A
This commit is contained in:
tidely 2025-06-05 18:57:27 +03:00 committed by GitHub
parent 32d5a2cca0
commit 738cfdff84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1351,7 +1351,7 @@ fn apply_font_features(
} }
#[inline] #[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); let tag = make_direct_write_tag(feature_name);
DWRITE_FONT_FEATURE { DWRITE_FONT_FEATURE {
nameTag: tag, nameTag: tag,
@ -1360,17 +1360,14 @@ fn make_direct_write_feature(feature_name: &str, parameter: u32) -> DWRITE_FONT_
} }
#[inline] #[inline]
fn make_open_type_tag(tag_name: &str) -> u32 { const fn make_open_type_tag(tag_name: &str) -> u32 {
let bytes = tag_name.bytes().collect_vec(); let bytes = tag_name.as_bytes();
assert_eq!(bytes.len(), 4); debug_assert!(bytes.len() == 4);
((bytes[3] as u32) << 24) u32::from_le_bytes([bytes[0], bytes[1], bytes[2], bytes[3]])
| ((bytes[2] as u32) << 16)
| ((bytes[1] as u32) << 8)
| (bytes[0] as u32)
} }
#[inline] #[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)) DWRITE_FONT_FEATURE_TAG(make_open_type_tag(tag_name))
} }