提交 e539889c authored 作者: Noel Grandin's avatar Noel Grandin

improve naming in FileNioMemData

上级 9b7dc1d0
...@@ -17,7 +17,6 @@ import java.util.LinkedHashMap; ...@@ -17,7 +17,6 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.compress.CompressLZF; import org.h2.compress.CompressLZF;
import org.h2.message.DbException; import org.h2.message.DbException;
...@@ -404,11 +403,11 @@ class FileNioMemData { ...@@ -404,11 +403,11 @@ class FileNioMemData {
private static final byte[] BUFFER = new byte[BLOCK_SIZE * 2]; private static final byte[] BUFFER = new byte[BLOCK_SIZE * 2];
private static final ByteBuffer COMPRESSED_EMPTY_BLOCK; private static final ByteBuffer COMPRESSED_EMPTY_BLOCK;
private static final Cache<CompressItem, CompressItem> COMPRESS_LATER = private static final CompressLaterCache<CompressItem, CompressItem> COMPRESS_LATER =
new Cache<CompressItem, CompressItem>(CACHE_SIZE); new CompressLaterCache<CompressItem, CompressItem>(CACHE_SIZE);
private String name; private String name;
private final int id; private final int nameHashCode;
private final boolean compress; private final boolean compress;
private long length; private long length;
private ByteBuffer[] data; private ByteBuffer[] data;
...@@ -426,16 +425,12 @@ class FileNioMemData { ...@@ -426,16 +425,12 @@ class FileNioMemData {
FileNioMemData(String name, boolean compress) { FileNioMemData(String name, boolean compress) {
this.name = name; this.name = name;
this.id = name.hashCode(); this.nameHashCode = name.hashCode();
this.compress = compress; this.compress = compress;
data = new ByteBuffer[0]; data = new ByteBuffer[0];
lastModified = System.currentTimeMillis(); lastModified = System.currentTimeMillis();
} }
int getId() {
return id;
}
/** /**
* Lock the file in exclusive mode if possible. * Lock the file in exclusive mode if possible.
* *
...@@ -476,12 +471,12 @@ class FileNioMemData { ...@@ -476,12 +471,12 @@ class FileNioMemData {
/** /**
* This small cache compresses the data if an element leaves the cache. * This small cache compresses the data if an element leaves the cache.
*/ */
static class Cache<K, V> extends LinkedHashMap<K, V> { static class CompressLaterCache<K, V> extends LinkedHashMap<K, V> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private final int size; private final int size;
Cache(int size) { CompressLaterCache(int size) {
super(size, (float) 0.75, true); super(size, (float) 0.75, true);
this.size = size; this.size = size;
} }
...@@ -505,16 +500,21 @@ class FileNioMemData { ...@@ -505,16 +500,21 @@ class FileNioMemData {
/** /**
* The file data. * The file data.
*/ */
FileNioMemData data; public final FileNioMemData data;
/** /**
* The page to compress. * The page to compress.
*/ */
int page; public final int page;
public CompressItem(FileNioMemData data, int page) {
this.data = data;
this.page = page;
}
@Override @Override
public int hashCode() { public int hashCode() {
return page ^ data.getId(); return page ^ data.nameHashCode;
} }
@Override @Override
...@@ -528,10 +528,8 @@ class FileNioMemData { ...@@ -528,10 +528,8 @@ class FileNioMemData {
} }
private void compressLater(int page) { private void addToCompressLaterCache(int page) {
CompressItem c = new CompressItem(); CompressItem c = new CompressItem(this, page);
c.data = this;
c.page = page;
synchronized (LZF) { synchronized (LZF) {
COMPRESS_LATER.put(c, c); COMPRESS_LATER.put(c, c);
} }
...@@ -615,7 +613,7 @@ class FileNioMemData { ...@@ -615,7 +613,7 @@ class FileNioMemData {
d.put(i, (byte) 0); d.put(i, (byte) 0);
} }
if (compress) { if (compress) {
compressLater(lastPage); addToCompressLaterCache(lastPage);
} }
} }
} }
...@@ -677,7 +675,7 @@ class FileNioMemData { ...@@ -677,7 +675,7 @@ class FileNioMemData {
b.position(oldPosition); b.position(oldPosition);
} }
if (compress) { if (compress) {
compressLater(page); addToCompressLaterCache(page);
} }
off += l; off += l;
pos += l; pos += l;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论