diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/FileNameCache.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/FileNameCache.java index 15f6b6475b77..c663e66ecad2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/FileNameCache.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/FileNameCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.vfs.newvfs.persistent.FSRecords; import com.intellij.util.IntSLRUCache; import com.intellij.util.containers.IntObjectLinkedMap; -import com.intellij.util.io.IOUtil; import com.intellij.util.io.PersistentStringEnumerator; import com.intellij.util.text.ByteArrayCharSequence; import org.jetbrains.annotations.NotNull; @@ -52,7 +51,7 @@ public class FileNameCache { throw new RuntimeException("VFS name enumerator corrupted"); } - CharSequence rawName = convertToBytesIfAsciiString(name); + CharSequence rawName = ByteArrayCharSequence.convertToBytesIfAsciiString(name); IntObjectLinkedMap.MapEntry entry = new IntObjectLinkedMap.MapEntry(id, rawName); IntSLRUCache> cache = ourNameCache[stripe]; //noinspection SynchronizationOnLocalVariableOrMethodParameter @@ -73,22 +72,6 @@ public class FileNameCache { return h % ourNameCache.length; } - @NotNull - private static CharSequence convertToBytesIfAsciiString(@NotNull String name) { - int length = name.length(); - if (length == 0) return ""; - - if (!IOUtil.isAscii(name)) { - return new String(name); // So we don't hold whole char[] buffer of a lengthy path on JDK 6 - } - - byte[] bytes = new byte[length]; - for (int i = 0; i < length; i++) { - bytes[i] = (byte)name.charAt(i); - } - return new ByteArrayCharSequence(bytes); - } - @NotNull private static IntObjectLinkedMap.MapEntry getEntry(int id) { assert id > 0; diff --git a/platform/util/src/com/intellij/util/text/ByteArrayCharSequence.java b/platform/util/src/com/intellij/util/text/ByteArrayCharSequence.java index 2292249b7e91..843d0664f127 100644 --- a/platform/util/src/com/intellij/util/text/ByteArrayCharSequence.java +++ b/platform/util/src/com/intellij/util/text/ByteArrayCharSequence.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ package com.intellij.util.text; +import com.intellij.util.io.IOUtil; import org.jetbrains.annotations.NotNull; public class ByteArrayCharSequence implements CharSequence { @@ -34,6 +35,7 @@ public class ByteArrayCharSequence implements CharSequence { return (char)myChars[index]; } + @NotNull @Override public CharSequence subSequence(int start, int end) { return start == 0 && end == length() ? this : new CharSequenceSubSequence(this, start, end); @@ -45,4 +47,19 @@ public class ByteArrayCharSequence implements CharSequence { return StringFactory.createShared(CharArrayUtil.fromSequence(this, 0, length())); } + @NotNull + public static CharSequence convertToBytesIfAsciiString(@NotNull String name) { + int length = name.length(); + if (length == 0) return ""; + + if (!IOUtil.isAscii(name)) { + return new String(name); // So we don't hold whole char[] buffer of a lengthy path on JDK 6 + } + + byte[] bytes = new byte[length]; + for (int i = 0; i < length; i++) { + bytes[i] = (byte)name.charAt(i); + } + return new ByteArrayCharSequence(bytes); + } }