private void addOccurrence(CharSequence charSequence, char[] chars, int start, int end, int occurrenceMask) {
    if (end == start || occurrenceMask == 0) return;
    int hash, hashNoCase;
    boolean hasArray = chars != null;
    if (IdIndexEntry.useStrongerHash()) {
      hash = hashNoCase = 0;
      boolean different = false;
      for (int off = start; off < end; off++) {
        char c = hasArray ? chars[off] : charSequence.charAt(off);
        char lowerC = StringUtil.toLowerCase(c);
        if (!different && c != lowerC) {
          different = true;
          hashNoCase = hash;
        }
        hash = 31 * hash + c;
        if (different) {
          hashNoCase = 31 * hashNoCase + lowerC;
        }
      }
      if (!different) {
        hashNoCase = hash;
      }
    }
    else {
      char firstChar = hasArray ? chars[start] : charSequence.charAt(start);
      char lastChar = hasArray ? chars[end - 1] : charSequence.charAt(end - 1);
      hash = (firstChar << 8) + (lastChar << 4) + end - start;
      char firstCharLower = StringUtil.toLowerCase(firstChar);
      char lastCharLower = StringUtil.toLowerCase(lastChar);
      hashNoCase = (firstCharLower == firstChar && lastCharLower == lastChar) ? hash :
                   (firstCharLower << 8) + (lastCharLower << 4) + end - start;
    }
    myOccurrences.mergeInt(hash, occurrenceMask, (prev, cur) -> prev | cur);

    if (hashNoCase != hash) {
      myOccurrences.mergeInt(hashNoCase, occurrenceMask, (prev, cur) -> prev | cur);
    }
  }
private void addOccurrence(CharSequence charSequence, char[] chars, int start, int end, int occurrenceMask)