From 635ed41dc97f6b86a9b0917610cbd1d8a7790ec2 Mon Sep 17 00:00:00 2001 From: Alexey Gopachenko Date: Wed, 13 Oct 2010 22:11:04 +0400 Subject: [PATCH] Spellchecker - its OK when word consists of completly UNKNOWN-TO-DICTIONARY symbols + IIOBE --- .../compress/CompressedDictionary.java | 3 +- .../spellchecker/compress/Encoder.java | 32 ++++--------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/compress/CompressedDictionary.java b/plugins/spellchecker/src/com/intellij/spellchecker/compress/CompressedDictionary.java index 14127d894d1e..9ff6f2882f47 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/compress/CompressedDictionary.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/compress/CompressedDictionary.java @@ -121,7 +121,8 @@ public final class CompressedDictionary implements Dictionary { } try { UnitBitSet bs = encoder.encode(word, false); - if (bs == null) return false; + if (bs == Encoder.WORD_OF_ENTIRELY_UNKNOWN_LETTERS) return true; + if (bs == null) return false; // fail faster w/o search byte[] compressed = UnitBitSet.getBytes(bs); int index = -1; for (int i = 0; i < lengths.length; i++) { diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/compress/Encoder.java b/plugins/spellchecker/src/com/intellij/spellchecker/compress/Encoder.java index 3bff5616c61d..5aba9c2fd77d 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/compress/Encoder.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/compress/Encoder.java @@ -9,6 +9,7 @@ public final class Encoder { private final Alphabet alphabet; private static final int offset = 2; + static final UnitBitSet WORD_OF_ENTIRELY_UNKNOWN_LETTERS = new UnitBitSet(); public Encoder() { alphabet = new Alphabet(); @@ -24,41 +25,22 @@ public final class Encoder { @Nullable public UnitBitSet encode(@NotNull CharSequence letters, boolean force) throws EncodingException { - if (UnitBitSet.MAX_CHARS_IN_WORD < letters.length()) return null; + if (UnitBitSet.MAX_CHARS_IN_WORD <= letters.length()) return null; + int unknownLetters = 0; UnitBitSet bs = new UnitBitSet(); - for (int i = 0; i < letters.length() - 1 + 1; i++) { + for (int i = 0; i < letters.length(); i++) { char letter = letters.charAt(i); int index = alphabet.getIndex(letter, force); - if (index<0) return null; + if (index < 0) unknownLetters++; bs.setUnitValue(i + offset, index); } bs.setUnitValue(0, letters.length()); bs.setUnitValue(1, bs.getUnitValue(2)); + if (unknownLetters == letters.length()) return WORD_OF_ENTIRELY_UNKNOWN_LETTERS; + if (unknownLetters>0) return null; return bs; } - //tested and OK - /* - public UnitBitSet encodex(@NotNull CharSequence letters, boolean force) throws EncodingException { - UnitBitSet bs = new UnitBitSet(alphabet.getMaxIndex(), false); - int bitsPerUnit = bs.bitsPerUnit; - long[] w = new long[(letters.length() + 2) * bitsPerUnit / Long.SIZE + 1]; - w[0] |= letters.length(); - w[0] |= alphabet.getIndex(letters.charAt(0), force) << bitsPerUnit; - for (int i = 0; i < letters.length(); i++) { - Character letter = letters.charAt(i); - int index = alphabet.getIndex(letter, force); - int startIndex = (i + offset) * bitsPerUnit; - w[startIndex / Long.SIZE] |= ((long)index) << (startIndex % Long.SIZE); - if (startIndex % Long.SIZE + bitsPerUnit > Long.SIZE) { - w[startIndex / Long.SIZE + 1] |= ((long)index) >>> (Long.SIZE - startIndex % Long.SIZE); - } - } - bs.setWords(w); - return bs; - } - */ - public String decode(@NotNull UnitBitSet bitSet) throws EncodingException { int wordLength = bitSet.getUnitValue(0); char firstLetter = alphabet.getLetter(bitSet.getUnitValue(1));