提交 13ece895 编写于 作者: V Vlad Ilyushchenko

chore: consolidated usage of toString()

上级 d7b31fcd
......@@ -41,7 +41,7 @@ public class DefaultCairoConfiguration implements CairoConfiguration {
private final TextConfiguration textConfiguration = new DefaultTextConfiguration();
public DefaultCairoConfiguration(CharSequence root) {
this.root = Chars.stringOf(root);
this.root = Chars.toString(root);
}
@Override
......
......@@ -89,7 +89,7 @@ public class TableReader implements Closeable {
LOG.info().$("open '").utf8(tableName).$('\'').$();
this.configuration = configuration;
this.ff = configuration.getFilesFacade();
this.tableName = Chars.stringOf(tableName);
this.tableName = Chars.toString(tableName);
this.path = new Path().of(configuration.getRoot()).concat(tableName);
this.rootLen = path.length();
try {
......
......@@ -142,7 +142,7 @@ public class TableWriter implements Closeable {
this.fileOperationRetryCount = configuration.getFileOperationRetryCount();
this.path = new Path().of(configuration.getRoot()).concat(name);
this.other = new Path().of(configuration.getRoot()).concat(name);
this.name = Chars.stringOf(name);
this.name = Chars.toString(name);
this.rootLen = path.length();
try {
if (lock) {
......
......@@ -489,7 +489,7 @@ public class CairoLineProtoParser implements LineProtoParser, Closeable {
entry = writerCache.valueAt(entryIndex);
} else {
entry = new CacheEntry();
writerCache.putAt(entryIndex, Chars.stringOf(tableName), entry);
writerCache.putAt(entryIndex, Chars.toString(tableName), entry);
// adjust writer map index to negative, which indicates that entry exists
entryIndex = -entryIndex - 1;
}
......
......@@ -55,6 +55,15 @@ public class TextMetadataParser implements JsonParser, Mutable, Closeable {
private static final int P_LOCALE = 4;
private static final int P_UTF8 = 5;
private static final CharSequenceIntHashMap propertyNameMap = new CharSequenceIntHashMap();
static {
propertyNameMap.put("name", P_NAME);
propertyNameMap.put("type", P_TYPE);
propertyNameMap.put("pattern", P_PATTERN);
propertyNameMap.put("locale", P_LOCALE);
propertyNameMap.put("utf8", P_UTF8);
}
private final DateLocaleFactory dateLocaleFactory;
private final TimestampLocaleFactory timestampLocaleFactory;
private final ObjectPool<FloatingCharSequence> csPool;
......@@ -87,6 +96,22 @@ public class TextMetadataParser implements JsonParser, Mutable, Closeable {
this.typeManager = typeManager;
}
private static void strcpyw(final CharSequence value, final int len, final long address) {
for (int i = 0; i < len; i++) {
Unsafe.getUnsafe().putChar(address + (i << 1), value.charAt(i));
}
}
private static void checkInputs(int position, CharSequence name, int type) throws JsonException {
if (name == null) {
throw JsonException.$(position, "Missing 'name' property");
}
if (type == -1) {
throw JsonException.$(position, "Missing 'type' property");
}
}
@Override
public void clear() {
bufSize = 0;
......@@ -172,16 +197,6 @@ public class TextMetadataParser implements JsonParser, Mutable, Closeable {
}
}
private static void checkInputs(int position, CharSequence name, int type) throws JsonException {
if (name == null) {
throw JsonException.$(position, "Missing 'name' property");
}
if (type == -1) {
throw JsonException.$(position, "Missing 'type' property");
}
}
private void clearStage() {
name = null;
type = -1;
......@@ -204,7 +219,7 @@ public class TextMetadataParser implements JsonParser, Mutable, Closeable {
bufCapacity = n * 2;
}
Chars.strcpyw(tag, l / 2, buf + bufSize);
strcpyw(tag, l / 2, buf + bufSize);
CharSequence cs = csPool.next().of(bufSize, l / 2);
bufSize += l;
return cs;
......@@ -283,12 +298,4 @@ public class TextMetadataParser implements JsonParser, Mutable, Closeable {
return this;
}
}
static {
propertyNameMap.put("name", P_NAME);
propertyNameMap.put("type", P_TYPE);
propertyNameMap.put("pattern", P_PATTERN);
propertyNameMap.put("locale", P_LOCALE);
propertyNameMap.put("utf8", P_UTF8);
}
}
......@@ -87,7 +87,7 @@ public class JoinRecordMetadata extends BaseRecordMetadata implements Closeable
if (dot == -1) {
cm = new TableColumnMetadata(b.put(tableAlias).put('.').put(columnName).toString(), columnType);
} else {
cm = new TableColumnMetadata(Chars.stringOf(columnName), columnType);
cm = new TableColumnMetadata(Chars.toString(columnName), columnType);
}
this.columnMetadata.add(cm);
......
......@@ -48,7 +48,7 @@ public class CreateTableModel implements Mutable, ExecutionModel, Sinkable, Tabl
public boolean addColumn(CharSequence name, int type, int symbolCapacity) {
if (columnNameIndexMap.put(name, columnNames.size())) {
columnNames.add(Chars.stringOf(name));
columnNames.add(Chars.toString(name));
columnBits.add(Numbers.encodeLowHighInts(type, symbolCapacity));
columnBits.add(Numbers.encodeLowHighInts(COLUMN_FLAG_CACHED, 0));
return true;
......
......@@ -60,7 +60,7 @@ public class CharSequenceIntHashMap extends AbstractCharSequenceHashSet {
if (index < 0) {
values[-index - 1] = values[-index - 1] + 1;
} else {
putAt0(index, key.toString(), 0);
putAt0(index, Chars.toString(key), 0);
}
}
......@@ -117,7 +117,7 @@ public class CharSequenceIntHashMap extends AbstractCharSequenceHashSet {
values[-index - 1] = value;
return false;
}
String keyString = key.toString();
final String keyString = Chars.toString(key);
putAt0(index, keyString, value);
list.add(keyString);
return true;
......@@ -130,7 +130,7 @@ public class CharSequenceIntHashMap extends AbstractCharSequenceHashSet {
public void putIfAbsent(CharSequence key, int value) {
int index = keyIndex(key);
if (index > -1) {
putAt0(index, key.toString(), value);
putAt0(index, Chars.toString(key), value);
}
}
......
......@@ -35,31 +35,6 @@ public final class Chars {
private Chars() {
}
public static int compare(CharSequence l, CharSequence r) {
if (l == r) {
return 0;
}
if (l == null) {
return -1;
}
if (r == null) {
return 1;
}
int ll = l.length();
int rl = r.length();
for (int i = 0, n = Math.min(ll, rl); i < n; i++) {
int k = l.charAt(i) - r.charAt(i);
if (k != 0) {
return k;
}
}
return Integer.compare(ll, rl);
}
public static boolean contains(CharSequence sequence, CharSequence term) {
int m = term.length();
if (m == 0) {
......@@ -120,7 +95,11 @@ public final class Chars {
return false;
}
for (int i = 0; i < ll; i++) {
return equalsChars(l, r, ll);
}
private static boolean equalsChars(CharSequence l, CharSequence r, int len) {
for (int i = 0; i < len; i++) {
if (l.charAt(i) != r.charAt(i)) {
return false;
}
......@@ -217,6 +196,24 @@ public final class Chars {
return true;
}
public static String toLowerCaseAscii(@Nullable CharSequence value) {
if (value == null) {
return null;
}
final int len = value.length();
if (len == 0) {
return "";
}
final CharSink b = Misc.getThreadLocalBuilder();
for (int i = 0; i < len; i++) {
b.put(toLowerCaseAscii(value.charAt(i)));
}
return b.toString();
}
public static boolean equalsLowerCaseAscii(@NotNull CharSequence l, CharSequence r) {
int ll;
if ((ll = l.length()) != r.length()) {
......@@ -408,17 +405,8 @@ public final class Chars {
}
public static boolean startsWith(CharSequence _this, CharSequence that) {
int len = that.length();
if (_this.length() < len) {
return false;
}
for (int i = 0; i < len; i++) {
if (_this.charAt(i) != that.charAt(i)) {
return false;
}
}
return true;
final int len = that.length();
return _this.length() >= len && equalsChars(_this, that, len);
}
public static boolean startsWith(CharSequence _this, int thisLo, int thisHi, CharSequence that) {
......@@ -446,29 +434,6 @@ public final class Chars {
}
}
public static void strcpy(final CharSequence value, final int lo, final int hi, final long address) {
for (int i = lo; i < hi; i++) {
Unsafe.getUnsafe().putByte(address + i - lo, (byte) value.charAt(i));
}
}
public static void strcpyw(final CharSequence value, final int len, final long address) {
for (int i = 0; i < len; i++) {
Unsafe.getUnsafe().putChar(address + (i << 1), value.charAt(i));
}
}
public static String stringOf(CharSequence charSequence) {
if (charSequence instanceof String) {
return (String) charSequence;
}
if (charSequence == null) {
return null;
}
return charSequence.toString();
}
public static char toLowerCaseAscii(char character) {
return character > 64 && character < 91 ? (char) (character + 32) : character;
}
......@@ -721,4 +686,30 @@ public final class Chars {
sink.put((char) (b1 << 6 ^ b2 ^ 3968));
return 2;
}
public static int compare(CharSequence l, CharSequence r) {
if (l == r) {
return 0;
}
if (l == null) {
return -1;
}
if (r == null) {
return 1;
}
final int ll = l.length();
final int rl = r.length();
final int min = Math.min(ll, rl);
for (int i = 0; i < min; i++) {
final int k = l.charAt(i) - r.charAt(i);
if (k != 0) {
return k;
}
}
return Integer.compare(ll, rl);
}
}
......@@ -56,7 +56,7 @@ public class GenericLexer implements ImmutableIterator<CharSequence> {
public GenericLexer(int poolCapacity) {
this.csPool = new ObjectPool<>(FloatingSequence::new, poolCapacity);
for (int i = 0, n = WHITESPACE.size(); i < n; i++) {
defineSymbol(WHITESPACE.get(i).toString());
defineSymbol(Chars.toString(WHITESPACE.get(i)));
}
}
......
......@@ -224,17 +224,17 @@ public class LongList implements Mutable {
*/
@Override
public String toString() {
CharSink toStringBuilder = Misc.getThreadLocalBuilder();
final CharSink sb = Misc.getThreadLocalBuilder();
toStringBuilder.put('[');
sb.put('[');
for (int i = 0, k = size(); i < k; i++) {
if (i > 0) {
toStringBuilder.put(',');
sb.put(',');
}
toStringBuilder.put(get(i));
sb.put(get(i));
}
toStringBuilder.put(']');
return toStringBuilder.toString();
sb.put(']');
return sb.toString();
}
public void increment(int index) {
......
......@@ -58,8 +58,7 @@ public class LowerCaseAsciiCharSequenceHashSet extends AbstractLowerCaseAsciiCha
}
public void addAt(int index, CharSequence key) {
String s = Chars.toString(key).toLowerCase();
keys[index] = s;
keys[index] = Chars.toLowerCaseAscii(key);
if (--free < 1) {
rehash();
}
......
......@@ -79,14 +79,14 @@ public class LowerCaseAsciiCharSequenceIntHashMap extends AbstractLowerCaseAscii
values[-index - 1] = value;
return false;
}
putAt0(index, key.toString().toLowerCase(), value);
putAt0(index, Chars.toLowerCaseAscii(key), value);
return true;
}
public void putIfAbsent(CharSequence key, int value) {
int index = keyIndex(key);
if (index > -1) {
putAt0(index, key.toString(), value);
putAt0(index, Chars.toLowerCaseAscii(key), value);
}
}
......
......@@ -82,7 +82,7 @@ public class LowerCaseAsciiCharSequenceObjHashMap<T> extends AbstractLowerCaseAs
return false;
}
final String lcKey = key.toString().toLowerCase();
final String lcKey = Chars.toLowerCaseAscii(key);
putAt0(index, lcKey, value);
list.add(lcKey);
return true;
......@@ -91,7 +91,7 @@ public class LowerCaseAsciiCharSequenceObjHashMap<T> extends AbstractLowerCaseAs
public void putIfAbsent(CharSequence key, T value) {
int index = keyIndex(key);
if (index > -1) {
putAt0(index, key.toString(), value);
putAt0(index, Chars.toLowerCaseAscii(key), value);
}
}
......
......@@ -204,7 +204,7 @@ public class DateFormatCompiler {
int op = opMap.get(cs);
if (op == -1) {
makeLastOpGreedy(ops);
delimiters.add(cs.toString());
delimiters.add(Chars.toString(cs));
ops.add(-(delimiters.size()));
} else {
if (op == OP_AM_PM) {
......
......@@ -25,9 +25,10 @@
package io.questdb.std.microtime;
import io.questdb.std.Chars;
import io.questdb.std.Misc;
import io.questdb.std.Numbers;
import io.questdb.std.NumericException;
import io.questdb.std.str.StringSink;
import io.questdb.std.str.CharSink;
final public class Timestamps {
......@@ -585,7 +586,7 @@ final public class Timestamps {
}
public static String toString(long micros) {
StringSink sink = new StringSink();
CharSink sink = Misc.getThreadLocalBuilder();
DateFormatUtils.appendDateTime(sink, micros);
return sink.toString();
}
......
......@@ -39,7 +39,7 @@ public abstract class AbstractCharSequence implements CharSequence, CloneableMut
@Override
@SuppressWarnings("unchecked")
public <T> T copy() {
return (T) this.toString();
return (T) AbstractCharSequence.getString(this);
}
@Override
......
......@@ -57,6 +57,12 @@ public class Path extends AbstractCharSink implements Closeable, LPSZ {
this.ptr = this.wptr = Unsafe.malloc(capacity + 1);
}
private static void strcpy(final CharSequence value, final int lo, final int hi, final long address) {
for (int i = lo; i < hi; i++) {
Unsafe.getUnsafe().putByte(address + i - lo, (byte) value.charAt(i));
}
}
public Path $() {
if (1 + (wptr - ptr) >= capacity) {
extend((int) (16 + (wptr - ptr)));
......@@ -145,7 +151,7 @@ public class Path extends AbstractCharSink implements Closeable, LPSZ {
if (l + len >= capacity) {
extend(l + len);
}
Chars.strcpy(cs, start, end, wptr);
strcpy(cs, start, end, wptr);
wptr += l;
len += l;
return this;
......
......@@ -197,7 +197,7 @@ public class DateFormatCompiler {
int op = opMap.get(cs);
if (op == -1) {
makeLastOpGreedy(ops);
delimiters.add(cs.toString());
delimiters.add(Chars.toString(cs));
ops.add(-(delimiters.size()));
} else {
if (op == OP_AM_PM) {
......
......@@ -25,6 +25,7 @@
package io.questdb.std.time;
import io.questdb.std.Chars;
import io.questdb.std.Misc;
import io.questdb.std.Numbers;
import io.questdb.std.NumericException;
import io.questdb.std.str.StringSink;
......@@ -556,7 +557,7 @@ final public class Dates {
}
public static String toString(long millis) {
StringSink sink = new StringSink();
StringSink sink = Misc.getThreadLocalBuilder();
DateFormatUtils.appendDateTime(sink, millis);
return sink.toString();
}
......
......@@ -67,7 +67,7 @@ public class TableModel implements TableStructure, Closeable {
}
public TableModel col(CharSequence name, int type) {
columnNames.add(Chars.stringOf(name));
columnNames.add(Chars.toString(name));
// set default symbol capacity
columnBits.add((128L << 32) | type);
columnBits.add(COLUMN_FLAG_CACHED);
......
......@@ -836,7 +836,7 @@ public class ReaderPoolTest extends AbstractCairoTest {
@Override
public void onEvent(byte factoryType, long thread, CharSequence name, short event, short segment, short position) {
names.add(name == null ? "" : Chars.stringOf(name));
names.add(name == null ? "" : Chars.toString(name));
events.add(event);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册