package com.intellij.util.text;

import com.intellij.openapi.util.SystemInfo;
import gnu.trove.TObjectHashingStrategy;

import java.io.File;

/**
 * @author max
 */
public class FilePathHashingStrategy implements TObjectHashingStrategy<String> {
  public int computeHashCode(final String s) {
    int h = 0;
    final int len = s.length();
    for( int i = 0; i < len; i++) {
      char c = normalizeChar(s.charAt(i));
      h = 31*h + c;
    }
    return h;
  }

  private static char normalizeChar(final char cc) {
    if (cc >= 'a' && cc <= 'z' || cc == '.' || cc == '/') return cc; // optimization
    if (cc >= 'A' && cc <= 'Z') return (char)(cc - 'A' + 'a');

    char c = SystemInfo.isFileSystemCaseSensitive ? cc : Character.toLowerCase(cc);
    return c == File.separatorChar ? '/' : c;
  }

  public boolean equals(final String s1, final String s2) {
    if(s1 == s2) return true;
    if(s1 == null || s2 == null) return false;
    if (s1.length() != s2.length()) return false;
    int len = s1.length();
    for (int i = 0; i < len; i++) {
      if (normalizeChar(s1.charAt(i)) != normalizeChar(s2.charAt(i))) return false;
    }

    return true;
  }
}

@@ -117,30 +117,8 @@
 y;%0A%0A
-import java.io.File;%0A%0A
 /**%0A
@@ -177,963 +177,289 @@
 egy 
-implements TObjectHashingStrategy%3CString%3E %7B%0A  public int computeHashCode(final String s) %7B%0A    int h = 0;%0A    final int len = s.length();%0A    for( int i = 0; i %3C len; i++) %7B%0A      char c = normalizeChar(s.charAt(i));%0A      h = 31*h + c;%0A    %7D%0A    return h;%0A  %7D%0A%0A  private static char normalizeChar(final char cc) %7B%0A    if (cc %3E= 'a' && cc %3C= 'z' %7C%7C cc == '.' %7C%7C cc == '/') return cc; // optimization%0A    if (cc %3E= 'A' && cc %3C= 'Z') return (char)(cc - 'A' + 'a');%0A%0A    char c = SystemInfo.isFileSystemCaseSensitive ? cc : Character.toLowerCase(cc);%0A    return c == File.separatorChar ? '/' : c;%0A  %7D%0A%0A  public boolean equals(final String s1, final String s2) %7B%0A    if(s1 == s2) return true;%0A    if(s1 == null %7C%7C s2 == null) return false;%0A    if (s1.length() != s2.length()) return false;%0A    int len = s1.length();%0A    for (int i = 0; i %3C len; i++) %7B%0A      if (normalizeChar(s1.charAt(i)) != normalizeChar(s2.charAt(i))) return false;%0A    %7D%0A%0A    return true
+%7B%0A  private FilePathHashingStrategy() %7B%0A  %7D%0A%0A  public static TObjectHashingStrategy%3CString%3E create() %7B%0A    //noinspection unchecked%0A    return SystemInfo.isFileSystemCaseSensitive%0A           ? TObjectHashingStrategy.CANONICAL%0A           : new CaseInsensitiveStringHashingStrategy()
 ;%0A  

drop inefficient FilePathHashingStrategy implementation