Unverified 提交 ed6735a0 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #1147 from katzyn/misc

Assorted minor optimizations
......@@ -415,7 +415,7 @@ public class Insert extends Prepared implements ResultTarget {
for (Column column : duplicateKeyAssignmentMap.keySet()) {
buff.appendExceptFirst(", ");
Expression ex = duplicateKeyAssignmentMap.get(column);
buff.append(column.getSQL()).append("=").append(ex.getSQL());
buff.append(column.getSQL()).append('=').append(ex.getSQL());
}
buff.append(" WHERE ");
Index foundIndex = (Index) de.getSource();
......
......@@ -1164,7 +1164,7 @@ public class Select extends Query {
buff.appendExceptFirst(",");
buff.append(c.getName());
}
buff.append(") AS ").append(t.getSQL()).append("\n");
buff.append(") AS ").append(t.getSQL()).append('\n');
}
}
}
......
......@@ -2492,7 +2492,7 @@ public class Function extends Expression implements FunctionCall {
StatementBuilder buff = new StatementBuilder(info.name);
if (info.type == CASE) {
if (args[0] != null) {
buff.append(" ").append(args[0].getSQL());
buff.append(' ').append(args[0].getSQL());
}
for (int i = 1, len = args.length - 1; i < len; i += 2) {
buff.append(" WHEN ").append(args[i].getSQL());
......
......@@ -10,11 +10,12 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.h2.util.SoftHashMap;
/**
......@@ -45,8 +46,7 @@ final class FullTextSettings {
/**
* The set of indexes in this database.
*/
private final Map<Integer, IndexInfo> indexes = Collections
.synchronizedMap(new HashMap<Integer, IndexInfo>());
private final ConcurrentHashMap<Integer, IndexInfo> indexes = new ConcurrentHashMap<>();
/**
* The prepared statement cache.
......
......@@ -491,8 +491,7 @@ public class PageDataIndex extends PageIndex {
Iterator<Row> getDelta() {
if (delta == null) {
List<Row> e = Collections.emptyList();
return e.iterator();
return Collections.emptyIterator();
}
return delta.iterator();
}
......
......@@ -251,8 +251,7 @@ public class ScanIndex extends BaseIndex {
Iterator<Row> getDelta() {
if (delta == null) {
List<Row> e = Collections.emptyList();
return e.iterator();
return Collections.emptyIterator();
}
return delta.iterator();
}
......
......@@ -258,7 +258,7 @@ public class MVPrimaryIndex extends BaseIndex {
ValueLong v = (ValueLong) (first ? map.firstKey() : map.lastKey());
if (v == null) {
return new MVStoreCursor(session,
Collections.<Entry<Value, Value>> emptyList().iterator());
Collections.<Entry<Value, Value>> emptyIterator());
}
Value value = map.get(v);
Entry<Value, Value> e = new AbstractMap.SimpleImmutableEntry<Value, Value>(v, value);
......
......@@ -307,7 +307,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
}
if (min == null) {
return new MVStoreCursor(session,
Collections.<Value>emptyList().iterator(), null);
Collections.<Value>emptyIterator(), null);
}
}
return new MVStoreCursor(session, map.keyIterator(min), last);
......@@ -394,7 +394,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
while (true) {
if (key == null) {
return new MVStoreCursor(session,
Collections.<Value>emptyList().iterator(), null);
Collections.<Value>emptyIterator(), null);
}
if (((ValueArray) key).getList()[0] != ValueNull.INSTANCE) {
break;
......
......@@ -21,6 +21,8 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.h2.Driver;
import org.h2.api.ErrorCode;
import org.h2.engine.Constants;
......@@ -49,8 +51,7 @@ public class TcpServer implements Service {
*/
private static final String MANAGEMENT_DB_PREFIX = "management_db_";
private static final Map<Integer, TcpServer> SERVERS =
Collections.synchronizedMap(new HashMap<Integer, TcpServer>());
private static final ConcurrentHashMap<Integer, TcpServer> SERVERS = new ConcurrentHashMap<>();
private int port;
private boolean portIsSet;
......
......@@ -9,10 +9,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.channels.FileChannel;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.h2.util.MathUtils;
/**
......@@ -25,7 +23,7 @@ public abstract class FilePath {
private static FilePath defaultProvider;
private static Map<String, FilePath> providers;
private static ConcurrentHashMap<String, FilePath> providers;
/**
* The prefix for temporary files.
......@@ -66,8 +64,7 @@ public abstract class FilePath {
private static void registerDefaultProviders() {
if (providers == null || defaultProvider == null) {
Map<String, FilePath> map = Collections.synchronizedMap(
new HashMap<String, FilePath>());
ConcurrentHashMap<String, FilePath> map = new ConcurrentHashMap<>();
for (String c : new String[] {
"org.h2.store.fs.FilePathDisk",
"org.h2.store.fs.FilePathMem",
......
......@@ -5,10 +5,7 @@
*/
package org.h2.util;
import java.util.Collections;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
/**
......@@ -17,10 +14,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class SynchronizedVerifier {
private static volatile boolean enabled;
private static final Map<Class<?>, AtomicBoolean> DETECT =
Collections.synchronizedMap(new HashMap<Class<?>, AtomicBoolean>());
private static final Map<Object, Object> CURRENT =
Collections.synchronizedMap(new IdentityHashMap<>());
private static final ConcurrentHashMap<Class<?>, AtomicBoolean> DETECT = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<Object, Object> CURRENT = new ConcurrentHashMap<>();
/**
* Enable or disable detection for a given class.
......
......@@ -265,7 +265,7 @@ public class ToDateParser {
while (p.hasToParseData()) {
List<ToDateTokenizer.FormatTokenEnum> tokenList =
ToDateTokenizer.FormatTokenEnum.getTokensInQuestion(p.getFormatStr());
if (tokenList.isEmpty()) {
if (tokenList == null) {
p.removeFirstChar();
continue;
}
......
......@@ -9,9 +9,7 @@ import static java.lang.String.format;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -616,10 +614,9 @@ class ToDateTokenizer {
// where "T" and "Z" are inlined
INLINE(PARSLET_INLINE, PATTERN_INLINE);
private static final List<FormatTokenEnum> EMPTY_LIST = Collections
.emptyList();
private static final List<FormatTokenEnum> INLINE_LIST = Collections.singletonList(INLINE);
private static final Map<Character, List<FormatTokenEnum>> CACHE = new HashMap<>(64);
private static List<FormatTokenEnum>[] TOKENS;
private final ToDateParslet toDateParslet;
private final Pattern patternToUse;
......@@ -648,59 +645,51 @@ class ToDateTokenizer {
/**
* Optimization: Only return a list of {@link FormatTokenEnum} that
* share the same 1st char using the 1st char of the 'to parse'
* formatStr. Or return empty list if no match.
* formatStr. Or return {@code null} if no match.
*
* @param formatStr the format string
* @return the list of tokens
* @return the list of tokens, or {@code null}
*/
static List<FormatTokenEnum> getTokensInQuestion(String formatStr) {
List<FormatTokenEnum> result = EMPTY_LIST;
if (CACHE.size() <= 0) {
initCache();
}
if (formatStr != null && formatStr.length() > 0) {
Character key = Character.toUpperCase(formatStr.charAt(0));
switch (key) {
case '"':
result = new ArrayList<>();
result.add(INLINE);
break;
default:
result = CACHE.get(key);
char key = Character.toUpperCase(formatStr.charAt(0));
if (key >= 'A' && key <= 'Y') {
List<FormatTokenEnum>[] tokens = TOKENS;
if (tokens == null) {
tokens = initTokens();
}
return tokens[key - 'A'];
} else if (key == '"') {
return INLINE_LIST;
}
}
if (result == null) {
result = EMPTY_LIST;
}
return result;
return null;
}
private static synchronized void initCache() {
if (CACHE.size() <= 0) {
for (FormatTokenEnum token : FormatTokenEnum.values()) {
List<Character> tokenKeys = new ArrayList<>();
if (token.name().contains("_")) {
String[] tokens = token.name().split("_");
for (String tokenLets : tokens) {
tokenKeys.add(tokenLets.toUpperCase().charAt(0));
}
} else {
tokenKeys.add(token.name().toUpperCase().charAt(0));
}
for (Character tokenKey : tokenKeys) {
List<FormatTokenEnum> l = CACHE.get(tokenKey);
if (l == null) {
l = new ArrayList<>(1);
CACHE.put(tokenKey, l);
}
l.add(token);
@SuppressWarnings("unchecked")
private static List<FormatTokenEnum>[] initTokens() {
List<FormatTokenEnum>[] tokens = new List[25];
for (FormatTokenEnum token : FormatTokenEnum.values()) {
String name = token.name();
if (name.indexOf('_') >= 0) {
for (String tokenLets : name.split("_")) {
putToCache(tokens, token, tokenLets);
}
} else {
putToCache(tokens, token, name);
}
}
return TOKENS = tokens;
}
private static void putToCache(List<FormatTokenEnum>[] cache, FormatTokenEnum token, String name) {
int idx = Character.toUpperCase(name.charAt(0)) - 'A';
List<FormatTokenEnum> l = cache[idx];
if (l == null) {
l = new ArrayList<>(1);
cache[idx] = l;
}
l.add(token);
}
/**
......
......@@ -10,9 +10,7 @@ import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* This sample application shows how to cache prepared statements.
......@@ -21,9 +19,7 @@ public class CachedPreparedStatements {
private Connection conn;
private Statement stat;
private final Map<String, PreparedStatement> prepared =
Collections.synchronizedMap(
new HashMap<String, PreparedStatement>());
private final ConcurrentHashMap<String, PreparedStatement> prepared = new ConcurrentHashMap<>();
/**
* This method is called when executing this sample application from the
......
......@@ -10,9 +10,8 @@ import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.h2.api.Trigger;
/**
......@@ -21,8 +20,7 @@ import org.h2.api.Trigger;
*/
public class TriggerPassData implements Trigger {
private static final Map<String, TriggerPassData> TRIGGERS =
Collections.synchronizedMap(new HashMap<String, TriggerPassData>());
private static final ConcurrentHashMap<String, TriggerPassData> TRIGGERS = new ConcurrentHashMap<>();
private String triggerData;
/**
......
......@@ -117,11 +117,16 @@ public class TestFuzzOptimizations extends TestBase {
}
executeAndCompare(condition, params, message);
}
if (!config.mvStore) {
if (!config.mvStore && config.travis) {
/*
* Travis tests have problems with automatic garbage collection, so request a GC
* explicitly and print its results.
*/
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
println((Utils.getMemoryUsed() >> 10) + " MiB used");
}
}
......
......@@ -98,12 +98,12 @@ public interface SQLDialect {
buff.append(index.indexName);
buff.append(" ON ");
buff.append(table);
buff.append("(");
buff.append('(');
for (String col : index.columnNames) {
buff.appendExceptFirst(", ");
buff.append(col);
}
buff.append(")");
buff.append(')');
return buff.toString();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论