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]
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))
}