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