moved useful convertToBytesIfAsciiString to util

This commit is contained in:
Alexey Kudravtsev
2015-05-15 15:31:52 +03:00
parent f49dd62a8e
commit 2c9ca8950f
2 changed files with 20 additions and 20 deletions
@@ -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<CharSequence> entry = new IntObjectLinkedMap.MapEntry<CharSequence>(id, rawName);
IntSLRUCache<IntObjectLinkedMap.MapEntry<CharSequence>> 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<CharSequence> getEntry(int id) {
assert id > 0;
@@ -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);
}
}