From 1ba421ef7c195d84bdb140af232b922014c8d812 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Reimar=20D=C3=B6ffinger?= Date: Sun, 30 Oct 2016 01:23:04 +0200 Subject: [PATCH] Avoid creating 100s of empty CachingLists. --- .../android/dictionary/engine/Index.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/com/hughes/android/dictionary/engine/Index.java b/src/com/hughes/android/dictionary/engine/Index.java index a664ce5..e52ac62 100644 --- a/src/com/hughes/android/dictionary/engine/Index.java +++ b/src/com/hughes/android/dictionary/engine/Index.java @@ -220,20 +220,24 @@ public final class Index implements RAFSerializable { normalizedToken = hasNormalizedForm ? raf.readUTF() : token; if (index.dict.dictFileVersion >= 7) { int size = StringUtil.readVarInt(raf); - final int[] htmlEntryIndices = new int[size]; - for (int i = 0; i < size; ++i) { - htmlEntryIndices[i] = StringUtil.readVarInt(raf); - } - this.htmlEntries = CachingList.create(new AbstractList() { - @Override - public HtmlEntry get(int i) { - return index.dict.htmlEntries.get(htmlEntryIndices[i]); - } - @Override - public int size() { - return htmlEntryIndices.length; + if (size == 0) { + this.htmlEntries = Collections.emptyList(); + } else { + final int[] htmlEntryIndices = new int[size]; + for (int i = 0; i < size; ++i) { + htmlEntryIndices[i] = StringUtil.readVarInt(raf); } - }, 1); + this.htmlEntries = CachingList.create(new AbstractList() { + @Override + public HtmlEntry get(int i) { + return index.dict.htmlEntries.get(htmlEntryIndices[i]); + } + @Override + public int size() { + return htmlEntryIndices.length; + } + }, 1); + } } else if (index.dict.dictFileVersion >= 6) { this.htmlEntries = CachingList.create( RAFList.create((RandomAccessFile)raf, index.dict.htmlEntryIndexSerializer, -- 2.43.0