Skip to content

Commit 096308e

Browse files
refactor: some cleanup and a performance improvement
1 parent 8f0bec2 commit 096308e

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

src/app.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,9 @@ impl eframe::App for PlistOxide {
356356
});
357357
})
358358
.body(|mut body| {
359-
let state = crate::widgets::entry::PlistEntry::new(
360-
Arc::clone(&self.state.root),
361-
vec![],
362-
)
363-
.show(&mut body);
359+
let state =
360+
crate::widgets::entry::PlistEntry::new(self.state.root.clone(), vec![])
361+
.show(&mut body);
364362
self.state.unsaved |= state != crate::widgets::entry::ChangeState::Unchanged;
365363
self.update_title(ctx);
366364
});

src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn pv_mut<'a>(path: &[String], mut p: &'a mut Value) -> &'a mut Value {
3131
pub fn child_keys(path: &[String], p: &Value) -> Vec<String> {
3232
match pv(path, p) {
3333
Value::Dictionary(v) => v.keys().cloned().collect(),
34-
Value::Array(v) => v.iter().enumerate().map(|(i, _)| i.to_string()).collect(),
34+
Value::Array(v) => (0..v.len()).map(|v| v.to_string()).collect(),
3535
_ => unreachable!(),
3636
}
3737
}

src/widgets/entry.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl PlistEntry {
169169
let keys = if ty.is_expandable() {
170170
child_keys(&path, &data.lock().unwrap())
171171
} else {
172-
vec![]
172+
Vec::new()
173173
};
174174
let mut ret = ChangeState::Unchanged;
175175
body.row(20.0, |mut row| {
@@ -274,23 +274,23 @@ impl PlistEntry {
274274
return;
275275
}
276276
row.col(|ui| {
277-
if !ty.is_expandable() {
278-
if PlistValue::new(&path, Arc::clone(&data)).show(ui) {
279-
ret |= ChangeState::Changed;
277+
if ty.is_expandable() {
278+
let len = keys.len();
279+
let s = if len == 1 { "" } else { "s" };
280+
match ty {
281+
ValueType::Array => {
282+
ui.add_enabled(false, Label::new(format!("{len} ordered object{s}")));
283+
}
284+
ValueType::Dictionary => {
285+
ui.add_enabled(false, Label::new(format!("{len} key/value pair{s}")));
286+
}
287+
_ => unreachable!(),
280288
}
281-
282289
return;
283290
}
284-
let len = keys.len();
285-
let s = if len == 1 { "" } else { "s" };
286-
match ty {
287-
ValueType::Array => {
288-
ui.add_enabled(false, Label::new(format!("{len} ordered object{s}")));
289-
}
290-
ValueType::Dictionary => {
291-
ui.add_enabled(false, Label::new(format!("{len} key/value pair{s}")));
292-
}
293-
_ => unreachable!(),
291+
292+
if PlistValue::new(&path, data.clone()).show(ui) {
293+
ret |= ChangeState::Changed;
294294
}
295295
});
296296
});
@@ -300,7 +300,7 @@ impl PlistEntry {
300300
if state.expanded {
301301
for k in keys {
302302
ret |= Self::new(
303-
Arc::clone(&data),
303+
data.clone(),
304304
path.iter().chain(std::iter::once(&k)).cloned().collect(),
305305
)
306306
.show(body);

0 commit comments

Comments
 (0)