Add Rope_length (mostly as a way to add __attribute__((pure)) to the codebase
[fur] / c / rope.c
index 716a5af..2cab922 100644 (file)
--- a/c/rope.c
+++ b/c/rope.c
@@ -87,4 +87,13 @@ Rope* Rope_concatenate(Rope* r0, Rope* r1) {
   return result;
 }
 
+__attribute__((pure)) size_t Rope_length(Rope* self) {
+  switch(self->type) {
+    case ROPETYPE_CONCATENATION:
+      return Rope_length(self->instance.concatenation.r0) + Rope_length(self->instance.concatenation.r0);
+    case ROPETYPE_STRING:
+      return self->instance.string.length;
+  }
+}
+
 #endif