From acebd05c04b34bb65fda773a1c5af43cb69dd92c Mon Sep 17 00:00:00 2001 From: Graham Date: Tue, 25 May 2021 23:35:11 +0100 Subject: [PATCH] Add comment explaining why we sort the constant pool entries Signed-off-by: Graham --- .../main/kotlin/org/openrs2/asm/packclass/ConstantPool.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/asm/src/main/kotlin/org/openrs2/asm/packclass/ConstantPool.kt b/asm/src/main/kotlin/org/openrs2/asm/packclass/ConstantPool.kt index 73413072..a336e5f1 100644 --- a/asm/src/main/kotlin/org/openrs2/asm/packclass/ConstantPool.kt +++ b/asm/src/main/kotlin/org/openrs2/asm/packclass/ConstantPool.kt @@ -43,6 +43,12 @@ public class ConstantPool private constructor( } public class Builder { + /* + * Sorting the entries provides two benefits: (1) the constant pool + * will compress better, as related entries are more likely to fit in + * the window, and (2) we can use binary search to speed up searching + * for an entry's index. + */ private val strings = ObjectAVLTreeSet() private val fieldNamesAndTypes = ObjectAVLTreeSet() private val methodNamesAndTypes = ObjectAVLTreeSet()