Skip to content

Commit 75fad25

Browse files
committed
perf!: cache UserData fields (#2572)
1 parent 3c9f619 commit 75fad25

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+803
-555
lines changed

Diff for: Cargo.lock

+36-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ md-5 = "0.10.6"
3232
mlua = { version = "0.10.3", features = [ "anyhow", "async", "error-send", "lua54", "macros", "serialize" ] }
3333
objc = "0.2.7"
3434
parking_lot = "0.12.3"
35+
paste = "1.0.15"
3536
ratatui = { version = "0.29.0", features = [ "unstable-rendered-line-info" ] }
3637
regex = "1.11.1"
3738
scopeguard = "1.2.0"

Diff for: yazi-adapter/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yazi-adapter"
3-
version = "25.3.7"
3+
version = "25.4.4"
44
edition = "2021"
55
license = "MIT"
66
authors = [ "sxyazi <[email protected]>" ]
@@ -9,9 +9,9 @@ homepage = "https://yazi-rs.github.io"
99
repository = "https://github.com/sxyazi/yazi"
1010

1111
[dependencies]
12-
yazi-config = { path = "../yazi-config", version = "25.3.7" }
13-
yazi-macro = { path = "../yazi-macro", version = "25.3.7" }
14-
yazi-shared = { path = "../yazi-shared", version = "25.3.7" }
12+
yazi-config = { path = "../yazi-config", version = "25.4.4" }
13+
yazi-macro = { path = "../yazi-macro", version = "25.4.4" }
14+
yazi-shared = { path = "../yazi-shared", version = "25.4.4" }
1515

1616
# External dependencies
1717
ansi-to-tui = { workspace = true }

Diff for: yazi-binding/Cargo.toml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "yazi-binding"
3+
version = "25.4.4"
4+
edition = "2021"
5+
license = "MIT"
6+
authors = [ "sxyazi <[email protected]>" ]
7+
description = "Yazi Lua bindings"
8+
homepage = "https://yazi-rs.github.io"
9+
repository = "https://github.com/sxyazi/yazi"
10+
11+
[dependencies]
12+
yazi-fs = { path = "../yazi-fs", version = "25.4.4" }
13+
yazi-macro = { path = "../yazi-macro", version = "25.4.4" }
14+
yazi-shared = { path = "../yazi-shared", version = "25.4.4" }
15+
mlua = { workspace = true }
16+
paste = { workspace = true }
17+
serde_json = { workspace = true }
File renamed without changes.

Diff for: yazi-binding/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mod macros;
2+
3+
yazi_macro::mod_flat!(error stage url);

Diff for: yazi-binding/src/macros.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#[macro_export]
2+
macro_rules! cached_field {
3+
($fields:ident, $key:ident, $value:expr) => {
4+
$fields.add_field_function_get(stringify!($key), |lua, ud| {
5+
use mlua::IntoLua;
6+
ud.borrow_mut_scoped::<Self, mlua::Result<mlua::Value>>(|me| {
7+
match paste::paste! { &me.[<v_ $key>] } {
8+
Some(v) => Ok(v.clone()),
9+
None => {
10+
let v: mlua::Result<_> = $value(lua, me);
11+
let v = v?.into_lua(lua)?;
12+
paste::paste! { me.[<v_ $key>] = Some(v.clone()) };
13+
Ok(v)
14+
}
15+
}
16+
})?
17+
});
18+
};
19+
}

Diff for: yazi-binding/src/stage.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use mlua::{IntoLuaMulti, MetaMethod, UserData, UserDataMethods};
2+
3+
pub struct FolderStage(yazi_fs::FolderStage);
4+
5+
impl FolderStage {
6+
pub fn new(inner: yazi_fs::FolderStage) -> Self { Self(inner) }
7+
}
8+
9+
impl UserData for FolderStage {
10+
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
11+
methods.add_meta_method(MetaMethod::Call, |lua, me, ()| {
12+
use yazi_fs::FolderStage::*;
13+
14+
match me.0 {
15+
Loading => false.into_lua_multi(lua),
16+
Loaded => true.into_lua_multi(lua),
17+
Failed(kind) => (true, crate::Error::IoKind(kind)).into_lua_multi(lua),
18+
}
19+
});
20+
}
21+
}

0 commit comments

Comments
 (0)