feat: flat tweaks and string interning
Co-authored-by: rvcas <x@rvcas.dev>
This commit is contained in:
@@ -44,7 +44,7 @@ impl Decode<'_> for char {
|
||||
|
||||
impl Decode<'_> for String {
|
||||
fn decode(d: &mut Decoder) -> Result<Self, String> {
|
||||
d.string()
|
||||
d.utf8()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,11 @@ impl<'b> Decoder<'b> {
|
||||
Ok(s)
|
||||
}
|
||||
|
||||
pub fn utf8(&mut self) -> Result<String, String> {
|
||||
// TODO: Better Error Handling
|
||||
Ok(String::from_utf8(Vec::<u8>::decode(self)?).unwrap())
|
||||
}
|
||||
|
||||
pub fn filler(&mut self) -> Result<(), String> {
|
||||
while self.zero()? {}
|
||||
Ok(())
|
||||
|
||||
@@ -46,7 +46,7 @@ impl Encode for char {
|
||||
|
||||
impl Encode for &str {
|
||||
fn encode(&self, e: &mut Encoder) -> Result<(), String> {
|
||||
e.string(*self)?;
|
||||
e.utf8(self)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -54,7 +54,7 @@ impl Encode for &str {
|
||||
|
||||
impl Encode for String {
|
||||
fn encode(&self, e: &mut Encoder) -> Result<(), String> {
|
||||
e.string(self)?;
|
||||
e.utf8(self)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ impl Encoder {
|
||||
self.word(c as usize);
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
// TODO: Do we need this?
|
||||
pub fn string(&mut self, s: &str) -> Result<&mut Self, String> {
|
||||
for i in s.chars() {
|
||||
self.one();
|
||||
@@ -87,6 +87,10 @@ impl Encoder {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn utf8(&mut self, s: &str) -> Result<&mut Self, String> {
|
||||
self.bytes(s.as_bytes())
|
||||
}
|
||||
|
||||
fn zero(&mut self) {
|
||||
if self.used_bits == 7 {
|
||||
self.next_word();
|
||||
|
||||
Reference in New Issue
Block a user