提交 2b0e00a1 authored 作者: Thomas Mueller's avatar Thomas Mueller

Reduce memory usage (spatial data is rare)

上级 87704274
...@@ -74,7 +74,7 @@ public class ValueDataType implements DataType { ...@@ -74,7 +74,7 @@ public class ValueDataType implements DataType {
final DataHandler handler; final DataHandler handler;
final CompareMode compareMode; final CompareMode compareMode;
final int[] sortTypes; final int[] sortTypes;
final SpatialDataType spatialType = new SpatialDataType(2); SpatialDataType spatialType;
public ValueDataType(CompareMode compareMode, DataHandler handler, public ValueDataType(CompareMode compareMode, DataHandler handler,
int[] sortTypes) { int[] sortTypes) {
...@@ -82,6 +82,13 @@ public class ValueDataType implements DataType { ...@@ -82,6 +82,13 @@ public class ValueDataType implements DataType {
this.handler = handler; this.handler = handler;
this.sortTypes = sortTypes; this.sortTypes = sortTypes;
} }
private SpatialDataType getSpatialDataType() {
if (spatialType == null) {
spatialType = new SpatialDataType(2);
}
return spatialType;
}
@Override @Override
public int compare(Object a, Object b) { public int compare(Object a, Object b) {
...@@ -137,7 +144,7 @@ public class ValueDataType implements DataType { ...@@ -137,7 +144,7 @@ public class ValueDataType implements DataType {
@Override @Override
public int getMemory(Object obj) { public int getMemory(Object obj) {
if (obj instanceof SpatialKey) { if (obj instanceof SpatialKey) {
return spatialType.getMemory(obj); return getSpatialDataType().getMemory(obj);
} }
return getMemory((Value) obj); return getMemory((Value) obj);
} }
...@@ -169,7 +176,7 @@ public class ValueDataType implements DataType { ...@@ -169,7 +176,7 @@ public class ValueDataType implements DataType {
public void write(WriteBuffer buff, Object obj) { public void write(WriteBuffer buff, Object obj) {
if (obj instanceof SpatialKey) { if (obj instanceof SpatialKey) {
buff.put((byte) SPATIAL_KEY_2D); buff.put((byte) SPATIAL_KEY_2D);
spatialType.write(buff, obj); getSpatialDataType().write(buff, obj);
return; return;
} }
Value x = (Value) obj; Value x = (Value) obj;
...@@ -566,7 +573,7 @@ public class ValueDataType implements DataType { ...@@ -566,7 +573,7 @@ public class ValueDataType implements DataType {
return ValueGeometry.get(b); return ValueGeometry.get(b);
} }
case SPATIAL_KEY_2D: case SPATIAL_KEY_2D:
return spatialType.read(buff); return getSpatialDataType().read(buff);
default: default:
if (type >= INT_0_15 && type < INT_0_15 + 16) { if (type >= INT_0_15 && type < INT_0_15 + 16) {
return ValueInt.get(type - INT_0_15); return ValueInt.get(type - INT_0_15);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论