From: David Kerkeslager Date: Tue, 20 Aug 2019 02:28:18 +0000 (-0400) Subject: Add Rope_length (mostly as a way to add __attribute__((pure)) to the codebase X-Git-Url: https://code.kerkeslager.com/?p=fur;a=commitdiff_plain;h=378e2971c2f78a9b79453bd47d2ddc658017a44d Add Rope_length (mostly as a way to add __attribute__((pure)) to the codebase --- diff --git a/c/rope.c b/c/rope.c index 716a5af..2cab922 100644 --- 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 diff --git a/c/rope.h b/c/rope.h index 33319e7..650596d 100644 --- 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