From bffc81cda97ccd18c505762f33b3b8318336da79 Mon Sep 17 00:00:00 2001 From: Mikhail Mitrofanov Date: Wed, 9 Sep 2026 11:04:02 +0300 Subject: [PATCH] Change text type in word to Box --- src/data/entities.rs | 14 +++++++------- src/main.rs | 6 ++++++ src/pages/dictionary.rs | 10 +++++----- src/pages/dictionary_quiz.rs | 8 ++++---- src/pages/history.rs | 6 +++--- src/pages/import.rs | 10 +++++----- src/pages/repetition.rs | 4 ++-- 7 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/data/entities.rs b/src/data/entities.rs index 4412064..99af1a1 100644 --- a/src/data/entities.rs +++ b/src/data/entities.rs @@ -14,12 +14,12 @@ use crate::data_provider::history::{HistoryRepository, HistoryRepositoryInner}; #[derive(Clone, Debug)] pub struct WordData { + pub additional: LiteMap, pub id: Id, pub group_id: Id, - pub key: String, - pub value: String, - pub tags: String, - pub additional: LiteMap, + pub key: Box, + pub value: Box, + pub tags: Box, } 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(), } diff --git a/src/main.rs b/src/main.rs index 90feca6..0e26e16 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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::()); + println!("Word size as value: {}", size_of::>()); + println!("Word size as value: {}", size_of::>()); env_logger::init(); start() } diff --git a/src/pages/dictionary.rs b/src/pages/dictionary.rs index 0435255..b12f557 100644 --- a/src/pages/dictionary.rs +++ b/src/pages/dictionary.rs @@ -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 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 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()); diff --git a/src/pages/dictionary_quiz.rs b/src/pages/dictionary_quiz.rs index d8fc4cf..d32c5ce 100644 --- a/src/pages/dictionary_quiz.rs +++ b/src/pages/dictionary_quiz.rs @@ -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(); } } diff --git a/src/pages/history.rs b/src/pages/history.rs index 7665efe..1ba880c 100644 --- a/src/pages/history.rs +++ b/src/pages/history.rs @@ -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()) diff --git a/src/pages/import.rs b/src/pages/import.rs index f444e7f..0e367b3 100644 --- a/src/pages/import.rs +++ b/src/pages/import.rs @@ -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); diff --git a/src/pages/repetition.rs b/src/pages/repetition.rs index 9e277b9..40fb2b1 100644 --- a/src/pages/repetition.rs +++ b/src/pages/repetition.rs @@ -56,7 +56,7 @@ impl NavigatedPage 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),