about summary refs log tree commit diff
path: root/users/tazjin
diff options
context:
space:
mode:
Diffstat (limited to 'users/tazjin')
-rw-r--r--users/tazjin/german-string/src/lib.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/users/tazjin/german-string/src/lib.rs b/users/tazjin/german-string/src/lib.rs
index c35cb3ad4464..813cd5b1e515 100644
--- a/users/tazjin/german-string/src/lib.rs
+++ b/users/tazjin/german-string/src/lib.rs
@@ -65,4 +65,21 @@ impl GermanString {
             GermanString(GSRepr { large })
         }
     }
+
+    fn len(&self) -> usize {
+        // SAFETY: The length field is located in the same location for both
+        // variants, reading it from either is safe.
+        unsafe { self.0.small.len as usize }
+    }
+}
+
+impl Drop for GermanString {
+    fn drop(&mut self) {
+        if self.len() > 12 {
+            let layout = Layout::array::<u8>(self.len()).unwrap();
+            unsafe {
+                std::alloc::dealloc(self.0.large.data, layout);
+            }
+        }
+    }
 }