aboutsummaryrefslogtreecommitdiff
path: root/src/megolm.c
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2016-05-24 16:58:51 +0100
committerRichard van der Hoff <richard@matrix.org>2016-05-24 17:38:43 +0100
commit1f31427139acdef00f24aac13b67224fa915f9e7 (patch)
tree2c1548cb0fa89bd1e37e4b9823219933b0e2fb9e /src/megolm.c
parentef8d24f4839352963f8d0b53919016c35f492a22 (diff)
megolm_advance_to: Remove excessive optimisation
There was some slightly overcomplex logic designed to save a couple of hash operations when R(0) and R(1) were advanced, but the extra code was hard to understand and didn't save much.
Diffstat (limited to 'src/megolm.c')
-rw-r--r--src/megolm.c29
1 files changed, 7 insertions, 22 deletions
diff --git a/src/megolm.c b/src/megolm.c
index 9e28f8d..6d8af08 100644
--- a/src/megolm.c
+++ b/src/megolm.c
@@ -106,6 +106,7 @@ void megolm_advance_to(Megolm *megolm, uint32_t advance_to) {
for (j = 0; j < (int)MEGOLM_RATCHET_PARTS; j++) {
int shift = (MEGOLM_RATCHET_PARTS-j-1) * 8;
uint32_t mask = (~(uint32_t)0) << shift;
+ int k;
/* how many times to we need to rehash this part? */
int steps = (advance_to >> shift) - (megolm->counter >> shift);
@@ -122,30 +123,14 @@ void megolm_advance_to(Megolm *megolm, uint32_t advance_to) {
steps --;
}
- /* on the last step (except for j=3), we need to bump at least R(j+1);
- * depending on the target count, we may also need to bump R(j+2) and
- * R(j+3).
+ /* on the last step we also need to bump R(j+1)...R(3).
+ *
+ * (Theoretically, we could skip bumping R(j+2) if we're going to bump
+ * R(j+1) again, but the code to figure that out is a bit baroque and
+ * doesn't save us much).
*/
- int k;
- switch(j) {
- case 0:
- if (!(advance_to & 0xFFFF00)) { k = 3; }
- else if (!(advance_to & 0xFF00)) { k = 2; }
- else { k = 1; }
- break;
- case 1:
- if (!(advance_to & 0xFF00)) { k = 3; }
- else { k = 2; }
- break;
- case 2:
- case 3:
- k = 3;
- break;
- }
-
- while (k >= j) {
+ for (k = 3; k >= j; k--) {
rehash_part(megolm->data, j, k);
- k--;
}
megolm->counter = advance_to & mask;
}