optimize with SmallString; consolidate related re-exports
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
ecc9099127
commit
b872f8e593
39 changed files with 113 additions and 96 deletions
|
@ -92,6 +92,8 @@ serde_json.workspace = true
|
|||
serde_regex.workspace = true
|
||||
serde_yaml.workspace = true
|
||||
serde.workspace = true
|
||||
smallvec.workspace = true
|
||||
smallstr.workspace = true
|
||||
thiserror.workspace = true
|
||||
tikv-jemallocator.optional = true
|
||||
tikv-jemallocator.workspace = true
|
||||
|
|
|
@ -10,14 +10,17 @@ pub mod pdu;
|
|||
pub mod server;
|
||||
pub mod utils;
|
||||
|
||||
pub use ::arrayvec;
|
||||
pub use ::http;
|
||||
pub use ::ruma;
|
||||
pub use ::smallstr;
|
||||
pub use ::smallvec;
|
||||
pub use ::toml;
|
||||
pub use ::tracing;
|
||||
pub use config::Config;
|
||||
pub use error::Error;
|
||||
pub use info::{rustc_flags_capture, version, version::version};
|
||||
pub use pdu::{Event, PduBuilder, PduCount, PduEvent, PduId, RawPduId};
|
||||
pub use pdu::{Event, PduBuilder, PduCount, PduEvent, PduId, RawPduId, StateKey};
|
||||
pub use server::Server;
|
||||
pub use utils::{ctor, dtor, implement, result, result::Result};
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ use ruma::{
|
|||
use serde::Deserialize;
|
||||
use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
|
||||
|
||||
use super::StateKey;
|
||||
|
||||
/// Build the start of a PDU in order to add it to the Database.
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Builder {
|
||||
|
@ -17,7 +19,7 @@ pub struct Builder {
|
|||
|
||||
pub unsigned: Option<Unsigned>,
|
||||
|
||||
pub state_key: Option<String>,
|
||||
pub state_key: Option<StateKey>,
|
||||
|
||||
pub redacts: Option<OwnedEventId>,
|
||||
|
||||
|
@ -29,15 +31,16 @@ pub struct Builder {
|
|||
type Unsigned = BTreeMap<String, serde_json::Value>;
|
||||
|
||||
impl Builder {
|
||||
pub fn state<T>(state_key: String, content: &T) -> Self
|
||||
pub fn state<S, T>(state_key: S, content: &T) -> Self
|
||||
where
|
||||
T: EventContent<EventType = StateEventType>,
|
||||
S: Into<StateKey>,
|
||||
{
|
||||
Self {
|
||||
event_type: content.event_type().into(),
|
||||
content: to_raw_value(content)
|
||||
.expect("Builder failed to serialize state event content to RawValue"),
|
||||
state_key: Some(state_key),
|
||||
state_key: Some(state_key.into()),
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ mod id;
|
|||
mod raw_id;
|
||||
mod redact;
|
||||
mod relation;
|
||||
mod state_key;
|
||||
mod strip;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
@ -17,7 +18,7 @@ use std::cmp::Ordering;
|
|||
|
||||
use ruma::{
|
||||
events::TimelineEventType, CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedEventId,
|
||||
OwnedRoomId, OwnedUserId, UInt,
|
||||
OwnedRoomId, OwnedServerName, OwnedUserId, UInt,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
@ -29,6 +30,7 @@ pub use self::{
|
|||
event_id::*,
|
||||
id::*,
|
||||
raw_id::*,
|
||||
state_key::{ShortStateKey, StateKey},
|
||||
Count as PduCount, Id as PduId, Pdu as PduEvent, RawId as RawPduId,
|
||||
};
|
||||
use crate::Result;
|
||||
|
@ -40,13 +42,13 @@ pub struct Pdu {
|
|||
pub room_id: OwnedRoomId,
|
||||
pub sender: OwnedUserId,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub origin: Option<String>,
|
||||
pub origin: Option<OwnedServerName>,
|
||||
pub origin_server_ts: UInt,
|
||||
#[serde(rename = "type")]
|
||||
pub kind: TimelineEventType,
|
||||
pub content: Box<RawJsonValue>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub state_key: Option<String>,
|
||||
pub state_key: Option<StateKey>,
|
||||
pub prev_events: Vec<OwnedEventId>,
|
||||
pub depth: UInt,
|
||||
pub auth_events: Vec<OwnedEventId>,
|
||||
|
|
8
src/core/pdu/state_key.rs
Normal file
8
src/core/pdu/state_key.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
use smallstr::SmallString;
|
||||
|
||||
use super::ShortId;
|
||||
|
||||
pub type StateKey = SmallString<[u8; INLINE_SIZE]>;
|
||||
pub type ShortStateKey = ShortId;
|
||||
|
||||
const INLINE_SIZE: usize = 48;
|
Loading…
Add table
Add a link
Reference in a new issue