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:
parent
32d5a2cca0
commit
738cfdff84
1 changed files with 6 additions and 9 deletions
|
@ -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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue