Change text type in word to Box<str>

This commit is contained in:
micialware committed 2026-09-09 11:04:02 +03:00
1 parent 4a71f31e6f
commit bffc81cda9
7 files changed
+32 -26

No files matched your search

+7 -7
View File
@@ -14,12 +14,12 @@ use crate::data_provider::history::{HistoryRepository, HistoryRepositoryInner};
#[derive(Clone, Debug)]
pub struct WordData {
pub additional: LiteMap<String, String>,
pub id: Id,
pub group_id: Id,
pub key: String,
pub value: String,
pub tags: String,
pub additional: LiteMap<String, String>,
pub key: Box<str>,
pub value: Box<str>,
pub tags: Box<str>,
}
impl EntityData for WordData {
@@ -52,9 +52,9 @@ impl WordData {
pub fn new() -> Self {
Self {
id: INVALID_ID,
key: String::new(),
value: String::new(),
tags: String::new(),
key: Box::from(""),
value: Box::from(""),
tags: Box::from(""),
additional: Default::default(),
group_id: 1.into(),
}
+6
View File
@@ -12,13 +12,19 @@ mod styling;
mod widgets;
pub mod tests;
use litemap::LiteMap;
use crate::app::start;
use mimalloc::MiMalloc;
use crate::data::entities::WordData;
use crate::data::Id;
#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;
fn main() -> iced::Result {
println!("Word size as value: {}", size_of::<Id>());
println!("Word size as value: {}", size_of::<Box<str>>());
println!("Word size as value: {}", size_of::<LiteMap<String, String>>());
env_logger::init();
start()
}
+5 -5
View File
@@ -26,7 +26,7 @@ use iced::{Border, Color, Shadow, Task};
use iced_core::Length::Fill;
use log::info;
use rand::random_range;
use std::ops::Add;
use std::ops::{Add, Deref};
use std::sync::Arc;
use std::time::{Duration, Instant};
@@ -124,13 +124,13 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
SetKey(handle, v) => {
let mut dictionary = self.state.dictionary.write();
dictionary.get_mut_static(handle).unwrap().key = v;
dictionary.get_mut_static(handle).unwrap().key = v.into_boxed_str();
drop(dictionary);
return self.launch_auto_save_offset(handle);
}
SetValue(handle, v) => {
let mut dictionary = self.state.dictionary.write();
dictionary.get_mut_static(handle).unwrap().value = v;
dictionary.get_mut_static(handle).unwrap().value = v.into_boxed_str();
drop(dictionary);
return self.launch_auto_save_offset(handle);
}
@@ -149,7 +149,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
v.remove(index);
}
word.tags = v;
word.tags = v.into_boxed_str();
}
self.update_tags();
@@ -511,7 +511,7 @@ impl DictionaryState {
let dict = &self.state.dictionary.write();
dict.iter().for_each(|element| {
split_with_coma(element.tags.as_str())
split_with_coma(element.tags.deref())
.iter()
.for_each(|tag| {
tags_list.insert(tag.clone());
+4 -4
View File
@@ -188,11 +188,11 @@ impl DictionaryQuizState {
let repo = self.state.dictionary.read();
let next = repo.get_static(next).unwrap();
if self.reverse {
self.view = next.value;
self.correct = next.key;
self.view = next.value.to_string();
self.correct = next.key.to_string();
} else {
self.view = next.key;
self.correct = next.value;
self.view = next.key.to_string();
self.correct = next.value.to_string();
}
}
+3 -3
View File
@@ -59,9 +59,9 @@ impl HistoryState {
let word = dict.get_static(handle).unwrap_or(WordData {
id: Default::default(),
group_id: Default::default(),
key: "Удаленное слово".to_string(),
value: "".to_string(),
tags: "".to_string(),
key: "Удаленное слово".into(),
value: Box::from(""),
tags: Box::from(""),
additional: Default::default(),
});
(word, item.clone())
+5 -5
View File
@@ -1,5 +1,5 @@
use crate::app::AppState;
use crate::data::entities::EntityData;
pub use crate::data::entities::{EntityData};
use crate::data::entities::WordData;
use crate::data::entities::WordGroup;
use crate::data_provider::import::{ImportData, ImportGroup, get_words_of_group, load_groups};
@@ -454,7 +454,7 @@ impl ImportState {
for import in import_list {
let mut word = WordData::new();
word.tags = import.tags.trim().replace(" ", ", ");
word.tags = import.tags.to_string().trim().replace(" ", ", ").into_boxed_str();
word.group_id = group_id;
for (dest, indices) in &map_indices {
let collected_string = Self::collect_strings(
@@ -465,13 +465,13 @@ impl ImportState {
);
match dest.as_str() {
"key" => {
word.key = collected_string;
word.key = collected_string.into_boxed_str();
}
"value" => {
word.value = collected_string;
word.value = collected_string.into_boxed_str();
}
"tags" => {
word.tags = collected_string;
word.tags = collected_string.into_boxed_str();
}
&_ => {
word.additional.insert((*dest).clone(), collected_string);
+2 -2
View File
@@ -56,7 +56,7 @@ impl NavigatedPage<RepetitionMessage> for RepetitionState {
self.can_play = false;
let value = self.current_word.key.clone();
if self.settings.require_speech() {
return Task::perform(play_sound(self.sink.clone(), value), |r| match r {
return Task::perform(play_sound(self.sink.clone(), value.to_string()), |r| match r {
Ok(_) => RootMessage::Repetition(RepetitionMessage::PlayFinished),
Err(err) => push_error!(err),
});
@@ -159,7 +159,7 @@ impl RepetitionState {
if self.settings.require_speech() && self.sink.is_some() {
let sink = self.sink.clone();
let task = play_sound(sink, self.current_word.key.clone());
let task = play_sound(sink, self.current_word.key.to_string());
return Task::perform(task, |r| match r {
Ok(_) => RootMessage::Repetition(RepetitionMessage::PlayFinished),
Err(err) => push_error!(err),