提交 82bc4287 编写于 作者: V Vlad Ilyushchenko

ALL: removed more unused code

上级 2073e15b
......@@ -27,6 +27,7 @@ import io.questdb.griffin.TypeEx;
import io.questdb.std.CharSequenceIntHashMap;
import io.questdb.std.IntObjHashMap;
import io.questdb.std.Long256;
import io.questdb.std.Unsafe;
import io.questdb.std.str.StringSink;
public final class ColumnType {
......@@ -48,6 +49,8 @@ public final class ColumnType {
private static final IntObjHashMap<String> typeNameMap = new IntObjHashMap<>();
private static final CharSequenceIntHashMap nameTypeMap = new CharSequenceIntHashMap();
private static final ThreadLocal<StringSink> caseConverterBuffer = ThreadLocal.withInitial(StringSink::new);
private static int[] TYPE_SIZE_POW2 = new int[ColumnType.PARAMETER + 1];
private static int[] TYPE_SIZE = new int[ColumnType.PARAMETER + 1];
static {
typeNameMap.put(BOOLEAN, "BOOLEAN");
......@@ -83,6 +86,32 @@ public final class ColumnType {
nameTypeMap.put("TIMESTAMP", TIMESTAMP);
nameTypeMap.put("CURSOR", TypeEx.CURSOR);
nameTypeMap.put("LONG256", ColumnType.LONG256);
TYPE_SIZE_POW2[ColumnType.BOOLEAN] = 0;
TYPE_SIZE_POW2[ColumnType.BYTE] = 0;
TYPE_SIZE_POW2[ColumnType.SHORT] = 1;
TYPE_SIZE_POW2[ColumnType.CHAR] = 1;
TYPE_SIZE_POW2[ColumnType.FLOAT] = 2;
TYPE_SIZE_POW2[ColumnType.INT] = 2;
TYPE_SIZE_POW2[ColumnType.SYMBOL] = 2;
TYPE_SIZE_POW2[ColumnType.DOUBLE] = 3;
TYPE_SIZE_POW2[ColumnType.LONG] = 3;
TYPE_SIZE_POW2[ColumnType.DATE] = 3;
TYPE_SIZE_POW2[ColumnType.TIMESTAMP] = 3;
TYPE_SIZE_POW2[ColumnType.LONG256] = 8;
TYPE_SIZE[ColumnType.BOOLEAN] = Byte.BYTES;
TYPE_SIZE[ColumnType.BYTE] = Byte.BYTES;
TYPE_SIZE[ColumnType.SHORT] = Short.BYTES;
TYPE_SIZE[ColumnType.CHAR] = Character.BYTES;
TYPE_SIZE[ColumnType.FLOAT] = Float.BYTES;
TYPE_SIZE[ColumnType.INT] = Integer.BYTES;
TYPE_SIZE[ColumnType.SYMBOL] = Integer.BYTES;
TYPE_SIZE[ColumnType.DOUBLE] = Double.BYTES;
TYPE_SIZE[ColumnType.LONG] = Long.BYTES;
TYPE_SIZE[ColumnType.DATE] = Long.BYTES;
TYPE_SIZE[ColumnType.TIMESTAMP] = Long.BYTES;
TYPE_SIZE[ColumnType.LONG256] = Long256.BYTES;
}
private ColumnType() {
......@@ -106,55 +135,13 @@ public final class ColumnType {
}
public static int pow2SizeOf(int columnType) {
switch (columnType) {
case ColumnType.BOOLEAN:
case ColumnType.BYTE:
return 0;
case ColumnType.DOUBLE:
case ColumnType.LONG:
case ColumnType.DATE:
case ColumnType.TIMESTAMP:
return 3;
case ColumnType.FLOAT:
case ColumnType.INT:
case ColumnType.SYMBOL:
return 2;
case ColumnType.SHORT:
case ColumnType.CHAR:
return 1;
case ColumnType.LONG256:
return 8;
default:
assert false : "Cannot request power of 2 for " + nameOf(columnType);
return -1;
}
return Unsafe.arrayGet(TYPE_SIZE_POW2, columnType);
}
public static int sizeOf(int columnType) {
switch (columnType) {
case ColumnType.BOOLEAN:
case ColumnType.BYTE:
return 1;
case ColumnType.DOUBLE:
case ColumnType.LONG:
case ColumnType.DATE:
case ColumnType.TIMESTAMP:
return 8;
case ColumnType.LONG256:
return Long256.BYTES;
case ColumnType.FLOAT:
case ColumnType.INT:
case ColumnType.SYMBOL:
return 4;
case ColumnType.SHORT:
case ColumnType.CHAR:
return 2;
case ColumnType.PARAMETER:
case ColumnType.STRING:
case ColumnType.BINARY:
return 0;
default:
return -1;
if (columnType < 0 || columnType > ColumnType.PARAMETER) {
return -1;
}
return Unsafe.arrayGet(TYPE_SIZE, columnType);
}
}
......@@ -44,8 +44,8 @@ public class TableReader implements Closeable {
private static final PartitionPathGenerator DEFAULT_GEN = (reader, partitionIndex) -> reader.pathGenDefault();
private static final ReloadMethod NON_PARTITIONED_RELOAD_METHOD = TableReader::reloadNonPartitioned;
private static final ReloadMethod FIRST_TIME_NON_PARTITIONED_RELOAD_METHOD = TableReader::reloadInitialNonPartitioned;
private static final ReloadMethod FIRST_TIME_PARTITIONED_RELOAD_METHOD = TableReader::reloadInitialPartitioned;
private static final ReloadMethod PARTITIONED_RELOAD_METHOD = TableReader::reloadPartitioned;
private static final ReloadMethod FIRST_TIME_PARTITIONED_RELOAD_METHOD = TableReader::reloadInitialPartitioned;
private static final TimestampFloorMethod ENTITY_FLOOR_METHOD = timestamp -> timestamp;
private final ColumnCopyStruct tempCopyStruct = new ColumnCopyStruct();
private final FilesFacade ff;
......@@ -169,31 +169,14 @@ public class TableReader implements Closeable {
}
private static void growColumn(ReadOnlyColumn mem1, ReadOnlyColumn mem2, int type, long rowCount) {
long offset;
long len;
if (rowCount > 0) {
// subtract column top
switch (type) {
case ColumnType.BINARY:
assert mem2 != null;
mem2.grow(rowCount * 8);
offset = mem2.getLong((rowCount - 1) * 8);
// grow data column to value offset + length, so that we can read length
mem1.grow(offset + 8);
len = mem1.getLong(offset);
if (len > 0) {
mem1.grow(offset + len + 8);
}
growBin(mem1, mem2, rowCount);
break;
case ColumnType.STRING:
assert mem2 != null;
mem2.grow(rowCount * 8);
offset = mem2.getLong((rowCount - 1) * 8);
mem1.grow(offset + 4);
len = mem1.getInt(offset);
if (len > 0) {
mem1.grow(offset + len * 2 + 4);
}
growStr(mem1, mem2, rowCount);
break;
default:
mem1.grow(rowCount << ColumnType.pow2SizeOf(type));
......@@ -202,6 +185,29 @@ public class TableReader implements Closeable {
}
}
private static void growStr(ReadOnlyColumn mem1, ReadOnlyColumn mem2, long rowCount) {
assert mem2 != null;
mem2.grow(rowCount * 8);
final long offset = mem2.getLong((rowCount - 1) * 8);
mem1.grow(offset + 4);
final long len = mem1.getInt(offset);
if (len > 0) {
mem1.grow(offset + len * 2 + 4);
}
}
private static void growBin(ReadOnlyColumn mem1, ReadOnlyColumn mem2, long rowCount) {
assert mem2 != null;
mem2.grow(rowCount * 8);
final long offset = mem2.getLong((rowCount - 1) * 8);
// grow data column to value offset + length, so that we can read length
mem1.grow(offset + 8);
final long len = mem1.getLong(offset);
if (len > 0) {
mem1.grow(offset + len + 8);
}
}
@Override
public void close() {
if (isOpen()) {
......
......@@ -24,7 +24,6 @@
package io.questdb.std;
import io.questdb.std.str.CharSink;
import io.questdb.std.str.DirectBytes;
import io.questdb.std.str.Path;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
......@@ -270,20 +269,6 @@ public final class Chars {
return h;
}
public static int hashCode(DirectBytes value) {
int len = value.byteLength();
if (len == 0) {
return 0;
}
int h = 0;
long address = value.address();
for (int p = 0, n = len / 2; p < n; p++) {
h = 31 * h + Unsafe.getUnsafe().getChar(address + (p << 1));
}
return h;
}
public static int indexOf(CharSequence s, char c) {
return indexOf(s, 0, c);
}
......
......@@ -46,44 +46,6 @@ public class DirectLongList implements Mutable, Closeable {
this.onePow2 = (1 << 3);
}
public void add(long x) {
ensureCapacity();
Unsafe.getUnsafe().putLong(pos, x);
pos += 8;
}
public final void add(DirectLongList that) {
int count = (int) (that.pos - that.start);
if (limit - pos < count) {
extend((int) (this.limit - this.start + count) >> 1);
}
Unsafe.getUnsafe().copyMemory(that.start, this.pos, count);
this.pos += count;
}
public int binarySearch(long v) {
int low = 0;
int high = (int) ((pos - start) >> 3) - 1;
while (low <= high) {
if (high - low < 65) {
return scanSearch(v);
}
int mid = (low + high) >>> 1;
long midVal = Unsafe.getUnsafe().getLong(start + (mid << 3));
if (midVal < v)
low = mid + 1;
else if (midVal > v)
high = mid - 1;
else
return mid;
}
return -(low + 1);
}
public void clear() {
clear(0);
}
......@@ -105,20 +67,6 @@ public class DirectLongList implements Mutable, Closeable {
return Unsafe.getUnsafe().getLong(start + (p << 3));
}
public int scanSearch(long v) {
int sz = size();
for (int i = 0; i < sz; i++) {
long f = get(i);
if (f == v) {
return i;
}
if (f > v) {
return -(i + 1);
}
}
return -(sz + 1);
}
public void set(long p, long v) {
assert p >= 0 && p <= (limit - start) >> 3;
Unsafe.getUnsafe().putLong(start + (p << 3), v);
......@@ -138,13 +86,6 @@ public class DirectLongList implements Mutable, Closeable {
return (int) ((pos - start) >> pow2);
}
public DirectLongList subset(int lo, int hi) {
DirectLongList that = new DirectLongList(hi - lo);
Unsafe.getUnsafe().copyMemory(start + (lo << 3), that.start, (hi - lo) << 3);
that.pos += (hi - lo) << 3;
return that;
}
@Override
public String toString() {
CharSink sb = Misc.getThreadLocalBuilder();
......@@ -163,12 +104,6 @@ public class DirectLongList implements Mutable, Closeable {
Unsafe.getUnsafe().setMemory(start, limit - start + onePow2, (byte) v);
}
void ensureCapacity() {
if (this.pos > limit) {
extend((int) ((limit - start + onePow2) >> (pow2 - 1)));
}
}
private void extend(long capacity) {
long address = Unsafe.malloc(this.capacity = ((capacity << pow2) + CACHE_LINE_SIZE));
long start = address + (address & (CACHE_LINE_SIZE - 1));
......
......@@ -25,6 +25,7 @@ package io.questdb.std;
public class Long256Util {
// this method is used by byte-code generator
public static int compare(Long256 a, Long256 b) {
if (a.getLong3() < b.getLong3()) {
......
......@@ -31,7 +31,6 @@ import java.util.concurrent.atomic.AtomicLong;
public final class Unsafe {
public static final long CHAR_OFFSET;
public static final long CHAR_SCALE;
public static final long BYTE_OFFSET;
public static final long INT_OFFSET;
public static final long INT_SCALE;
public static final long LONG_OFFSET;
......@@ -59,8 +58,6 @@ public final class Unsafe {
CHAR_OFFSET = Unsafe.getUnsafe().arrayBaseOffset(char[].class);
CHAR_SCALE = msb(Unsafe.getUnsafe().arrayIndexScale(char[].class));
BYTE_OFFSET = Unsafe.getUnsafe().arrayBaseOffset(byte[].class);
} catch (Exception e) {
throw new FatalError(e);
}
......
......@@ -40,10 +40,8 @@ public class TimestampLocale {
private final String[] ampmArray;
private final String[] eraArray;
private final TimeZoneRuleFactory factory;
private final String id;
TimestampLocale(String id, DateFormatSymbols symbols, TimeZoneRuleFactory timeZoneRuleFactory, @Transient CharSequenceHashSet cache) {
this.id = id;
TimestampLocale(DateFormatSymbols symbols, TimeZoneRuleFactory timeZoneRuleFactory, @Transient CharSequenceHashSet cache) {
this.factory = timeZoneRuleFactory;
index(monthArray = symbols.getMonths(), months);
index(shortMonthArray = symbols.getShortMonths(), months);
......@@ -120,10 +118,6 @@ public class TimestampLocale {
return Unsafe.arrayGet(eraArray, index);
}
public String getId() {
return id;
}
public String getMonth(int index) {
return Unsafe.arrayGet(monthArray, index);
}
......
......@@ -42,7 +42,7 @@ public class TimestampLocaleFactory {
if ("und".equals(tag)) {
tag = "";
}
dateLocales.put(tag, new TimestampLocale(tag, new DateFormatSymbols(l), timeZoneRuleFactory, cache));
dateLocales.put(tag, new TimestampLocale(new DateFormatSymbols(l), timeZoneRuleFactory, cache));
cache.clear();
}
defaultTimestampLocale = dateLocales.get(Locale.getDefault().toLanguageTag());
......
......@@ -29,20 +29,11 @@ import io.questdb.std.ObjectFactory;
import io.questdb.std.Unsafe;
import org.jetbrains.annotations.NotNull;
public class DirectByteCharSequence extends AbstractCharSequence implements Mutable, ByteSequence, DirectBytes {
public class DirectByteCharSequence extends AbstractCharSequence implements Mutable, ByteSequence {
public static final Factory FACTORY = new Factory();
private long lo;
private long hi;
@Override
public long address() {
return lo;
}
@Override
public int byteLength() {
return length();
}
@Override
public byte byteAt(int index) {
......
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (C) 2014-2019 Appsicle
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
package io.questdb.std.str;
public interface DirectBytes {
long address();
int byteLength();
}
......@@ -26,21 +26,11 @@ package io.questdb.std.str;
import io.questdb.std.Mutable;
import io.questdb.std.Unsafe;
public class DirectCharSequence extends AbstractCharSequence implements DirectBytes, Mutable {
public class DirectCharSequence extends AbstractCharSequence implements Mutable {
private long lo;
private long hi;
private int len;
@Override
public long address() {
return lo;
}
@Override
public int byteLength() {
return len * 2;
}
@Override
public void clear() {
hi = lo = 0;
......
......@@ -29,7 +29,7 @@ import org.jetbrains.annotations.NotNull;
import java.io.Closeable;
public class DirectCharSink extends AbstractCharSink implements CharSequence, Closeable, Mutable, DirectBytes {
public class DirectCharSink extends AbstractCharSink implements CharSequence, Closeable, Mutable {
private long ptr;
private int capacity;
private long lo;
......@@ -42,16 +42,6 @@ public class DirectCharSink extends AbstractCharSink implements CharSequence, Cl
this.hi = ptr + capacity;
}
@Override
public long address() {
return ptr;
}
@Override
public int byteLength() {
return (int) (lo - ptr);
}
@Override
public void clear() {
lo = ptr;
......
......@@ -40,10 +40,8 @@ public class DateLocale {
private final String[] ampmArray;
private final String[] eraArray;
private final TimeZoneRuleFactory factory;
private final String id;
DateLocale(String id, DateFormatSymbols symbols, TimeZoneRuleFactory timeZoneRuleFactory, @Transient CharSequenceHashSet cache) {
this.id = id;
DateLocale(DateFormatSymbols symbols, TimeZoneRuleFactory timeZoneRuleFactory, @Transient CharSequenceHashSet cache) {
this.factory = timeZoneRuleFactory;
index(monthArray = symbols.getMonths(), months);
index(shortMonthArray = symbols.getShortMonths(), months);
......@@ -66,10 +64,13 @@ public class DateLocale {
}
char c0 = Character.toUpperCase(token.charAt(0));
ObjList<CharSequence> l = map.get(c0);
if (l == null) {
int index = map.keyIndex(c0);
ObjList<CharSequence> l;
if (index > -1) {
l = new ObjList<>();
map.put(c0, l);
map.putAt(index, c0, l);
} else {
l = map.valueAt(index);
}
l.add(((char) pos) + token.toUpperCase());
l.sort(GenericLexer.COMPARATOR);
......@@ -117,10 +118,6 @@ public class DateLocale {
return Unsafe.arrayGet(eraArray, index);
}
public String getId() {
return id;
}
public String getMonth(int index) {
return Unsafe.arrayGet(monthArray, index);
}
......
......@@ -42,7 +42,7 @@ public class DateLocaleFactory {
if ("und".equals(tag)) {
tag = "";
}
dateLocales.put(tag, new DateLocale(tag, new DateFormatSymbols(l), timeZoneRuleFactory, cache));
dateLocales.put(tag, new DateLocale(new DateFormatSymbols(l), timeZoneRuleFactory, cache));
cache.clear();
}
defaultDateLocale = dateLocales.get(Locale.getDefault().toLanguageTag());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册