]> code.kerkeslager.com Git - fur/commitdiff
Add Rope_length (mostly as a way to add __attribute__((pure)) to the codebase
authorDavid Kerkeslager <kerkeslager@gmail.com>
Tue, 20 Aug 2019 02:28:18 +0000 (22:28 -0400)
committerDavid Kerkeslager <kerkeslager@gmail.com>
Tue, 20 Aug 2019 02:28:18 +0000 (22:28 -0400)
c/rope.c
c/rope.h

index 716a5af76e999592bf1359812a0742d78b250ef2..2cab922c3d158c4ae6eca52ea9f504e00aec449b 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
index 33319e71a84e1daaad0583fd69a7768fd75fec6e..650596d120689a2f1241f6e83acf18991b20b820 100644 (file)
--- a/c/rope.h
+++ b/c/rope.h
@@ -21,4 +21,6 @@ Rope* Rope_read(Encoding, FILE);
 
 Rope* Rope_concatenate(Rope* r0, Rope* r1);
 
+size_t Rope_length(Rope*) __attribute__((pure));
+
 #endif