Switch to finl_unicode for grapheme clustering

According to its benchmarks, it's almost 2x faster than
unicode_segmentation.  It doesn't appear to make a visible
difference to `time cat bigfile`, but I'll take anything
that gives more headroom for such little effort of switching.
This commit is contained in:
Wez Furlong committed 2022-09-10 07:15:49 -07:00
1 parent a0c2df2d86
commit 96c4e7e9b9
19 files changed
+53 -48

No files matched your search

+1 -1
View File
@@ -8,9 +8,9 @@ edition = "2021"
[dependencies]
anyhow = "1.0"
config = { path = "../../config" }
finl_unicode = "1.0.2"
terminfo = "0.7"
wezterm-dynamic = { path = "../../wezterm-dynamic" }
luahelper = { path = "../../luahelper" }
termwiz = { path = "../../termwiz", features=["use_serde"] }
unicode-segmentation = "1.8"
lazy_static = "1.4"
+4 -3
View File
@@ -1,5 +1,6 @@
use config::lua::get_or_create_module;
use config::lua::mlua::{self, Lua, ToLua};
use finl_unicode::grapheme_clusters::Graphemes;
use luahelper::impl_lua_conversion_dynamic;
use std::str::FromStr;
use termwiz::caps::{Capabilities, ColorLevel, ProbeHints};
@@ -8,7 +9,6 @@ use termwiz::color::{AnsiColor, ColorAttribute, ColorSpec, SrgbaTuple};
use termwiz::input::Modifiers;
use termwiz::render::terminfo::TerminfoRenderer;
use termwiz::surface::change::Change;
use unicode_segmentation::UnicodeSegmentation;
use wezterm_dynamic::{FromDynamic, ToDynamic};
pub fn register(lua: &Lua) -> anyhow::Result<()> {
@@ -170,7 +170,8 @@ pub fn pad_left(mut result: String, width: usize) -> String {
pub fn truncate_left(s: &str, max_width: usize) -> String {
let mut result = vec![];
let mut len = 0;
for g in s.graphemes(true).rev() {
let graphemes: Vec<_> = Graphemes::new(s).collect();
for &g in graphemes.iter().rev() {
let g_len = grapheme_column_width(g, None);
if g_len + len > max_width {
break;
@@ -186,7 +187,7 @@ pub fn truncate_left(s: &str, max_width: usize) -> String {
pub fn truncate_right(s: &str, max_width: usize) -> String {
let mut result = String::new();
let mut len = 0;
for g in s.graphemes(true) {
for g in Graphemes::new(s) {
let g_len = grapheme_column_width(g, None);
if g_len + len > max_width {
break;