mirror of
https://github.com/openharmony/third_party_rust_unicode-width.git
synced 2026-07-19 23:24:44 -04:00
add benchmarks ; add explicit #[inline] annotations
This diff adds benchmarks to get more info regarding Issue #1. It appears that the remaining difference between the "simple" case and the "cargo" case is the result of a difference in performance between using `match` and `if` for tight loops. I suspect it's because of the way that match arms get reordered: if I manually reorder the "if" statement, I can reproduce the match performance. Also added a couple #[inline] annotations in tables.rs, though the difference in performance in my measurements is negligible. Bumped version number to 0.1.1.
This commit is contained in:
@@ -206,6 +206,7 @@ def emit_charwidth_module(f, width_table):
|
||||
#[cfg(feature = "no_std")]
|
||||
use core::result::Result::{Ok, Err};
|
||||
|
||||
#[inline]
|
||||
fn bsearch_range_value_table(c: char, is_cjk: bool, r: &'static [(char, char, u8, u8)]) -> u8 {
|
||||
#[cfg(feature = "no_std")]
|
||||
use core::cmp::Ordering::{Equal, Less, Greater};
|
||||
@@ -226,6 +227,7 @@ def emit_charwidth_module(f, width_table):
|
||||
""")
|
||||
|
||||
f.write("""
|
||||
#[inline]
|
||||
pub fn width(c: char, is_cjk: bool) -> Option<usize> {
|
||||
match c as usize {
|
||||
_c @ 0 => Some(0), // null is zero width
|
||||
|
||||
Reference in New Issue
Block a user