save memory on detected line separator

This commit is contained in:
Alexey Kudravtsev
2014-02-28 13:34:44 +04:00
parent 0b40c676a5
commit 569077658c
4 changed files with 37 additions and 12 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -125,6 +125,7 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica
* @return the path
*/
@SuppressWarnings("JavadocReference")
@NotNull
public abstract String getPath();
/**
@@ -727,4 +728,12 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica
public static boolean isValidName(@NotNull String name) {
return name.indexOf('\\') < 0 && name.indexOf('/') < 0;
}
private static final Key<String> DETECTED_LINE_SEPARATOR_KEY = Key.create("DETECTED_LINE_SEPARATOR_KEY");
public String getDetectedLineSeparator() {
return getUserData(DETECTED_LINE_SEPARATOR_KEY);
}
public void setDetectedLineSeparator(String separator) {
putUserData(DETECTED_LINE_SEPARATOR_KEY, separator);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -40,7 +40,6 @@ import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
public final class LoadTextUtil {
private static final Key<String> DETECTED_LINE_SEPARATOR_KEY = Key.create("DETECTED_LINE_SEPARATOR_KEY");
@Nls private static final String AUTO_DETECTED_FROM_BOM = "auto-detected from BOM";
private LoadTextUtil() {
@@ -215,7 +214,7 @@ public final class LoadTextUtil {
}
String newText = StringUtil.convertLineSeparators(currentText.toString(), newSeparator);
file.putUserData(DETECTED_LINE_SEPARATOR_KEY, newSeparator);
file.setDetectedLineSeparator(newSeparator);
write(project, file, requestor, newText, -1);
}
@@ -397,7 +396,7 @@ public final class LoadTextUtil {
Pair<CharSequence, String> result = convertBytes(bytes, charset, offset);
if (saveDetectedSeparators) {
virtualFile.putUserData(DETECTED_LINE_SEPARATOR_KEY, result.getSecond());
virtualFile.setDetectedLineSeparator(result.getSecond());
}
return result.getFirst();
}
@@ -425,7 +424,7 @@ public final class LoadTextUtil {
}
static String getDetectedLineSeparator(@NotNull VirtualFile file) {
return file.getUserData(DETECTED_LINE_SEPARATOR_KEY);
return file.getDetectedLineSeparator();
}
@NotNull
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -24,6 +24,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
import com.intellij.openapi.vfs.newvfs.NewVirtualFileSystem;
import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS;
import com.intellij.util.LineSeparator;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -124,4 +125,19 @@ public class VirtualFileImpl extends VirtualFileSystemEntry {
public OutputStream getOutputStream(final Object requestor, final long modStamp, final long timeStamp) throws IOException {
return VfsUtilCore.outputStreamAddingBOM(ourPersistence.getOutputStream(this, requestor, modStamp, timeStamp), this);
}
@Override
public String getDetectedLineSeparator() {
if (getFlagInt(SYSTEM_LINE_SEPARATOR_DETECTED)) {
return LineSeparator.getSystemLineSeparator().getSeparatorString();
}
return super.getDetectedLineSeparator();
}
@Override
public void setDetectedLineSeparator(String separator) {
boolean hasSystemSeparator = LineSeparator.getSystemLineSeparator().getSeparatorString().equals(separator);
setFlagInt(SYSTEM_LINE_SEPARATOR_DETECTED, hasSystemSeparator);
super.setDetectedLineSeparator(hasSystemSeparator ? null : separator);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -52,14 +52,15 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile {
private static final Key<String> SYMLINK_TARGET = Key.create("local.vfs.symlink.target");
private static final int IS_WRITABLE_FLAG = 0x01000000;
private static final int IS_HIDDEN_FLAG = 0x02000000;
private static final int INDEXED_FLAG = 0x04000000;
static final int CHILDREN_CACHED = 0x08000000; // makes sense for directory only
private static final int DIRTY_FLAG = 0x10000000;
private static final int IS_SYMLINK_FLAG = 0x20000000;
private static final int HAS_SYMLINK_FLAG = 0x40000000;
private static final int IS_SPECIAL_FLAG = 0x80000000;
private static final int IS_WRITABLE_FLAG = 0x01000000;
private static final int IS_HIDDEN_FLAG = 0x02000000;
private static final int INDEXED_FLAG = 0x04000000;
static final int CHILDREN_CACHED = 0x08000000;
static final int SYSTEM_LINE_SEPARATOR_DETECTED = CHILDREN_CACHED; // makes sense only for non-directory file
private static final int ALL_FLAGS_MASK =
DIRTY_FLAG | IS_SYMLINK_FLAG | HAS_SYMLINK_FLAG | IS_SPECIAL_FLAG | IS_WRITABLE_FLAG | IS_HIDDEN_FLAG | INDEXED_FLAG | CHILDREN_CACHED;