Permalink
Browse files

Reduce map lookups in persistence

  • Loading branch information...
PseudoKnight committed Oct 24, 2017
1 parent d09df7b commit 7e4ebf423635c0a211661b00b40529932fb051ee
@@ -73,8 +73,9 @@ public static void DisconnectAll(){
*/
public static DataSource GetDataSource(URI uri, ConnectionMixinFactory.ConnectionMixinOptions options) throws DataSourceException {
init();
if(dataSourcePool.containsKey(uri)){
return dataSourcePool.get(uri);
DataSource source = dataSourcePool.get(uri);
if(source != null){
return source;
}
List<DataSource.DataSourceModifier> modifiers = new ArrayList<DataSource.DataSourceModifier>();
while (DataSource.DataSourceModifier.isModifier(uri.getScheme())) {
@@ -323,8 +323,9 @@ private boolean arrayContains(String[] array, String contains, int from, int to)
public URI getConnection(String key) {
//Since looking through these patterns, doing the matches, calculating string distance are all
//fairly expensive operations, let's improve the runtime complexity by using a cache
if (cache.containsKey(key)) {
return cache.get(key);
URI cached = cache.get(key);
if(cached != null){
return cached;
}
List<Pattern> matches = new ArrayList<Pattern>();
for (Pattern p : mappings.keySet()) {
@@ -36,8 +36,9 @@
*/
public static synchronized ThreadsafeDataSource GetDataSource(URI uri, ConnectionMixinFactory.ConnectionMixinOptions options) throws DataSourceException{
Pair<URI, ConnectionMixinFactory.ConnectionMixinOptions> pair = new Pair<>(uri, options);
if(sources.containsKey(pair) && sources.get(pair) != null){
return sources.get(pair);
ThreadsafeDataSource source = sources.get(pair);
if(source != null){
return source;
} else {
ThreadsafeDataSource ds = new ThreadsafeDataSource(DataSourceFactory.GetDataSource(uri, options));
sources.put(pair, ds);

0 comments on commit 7e4ebf4

Please sign in to comment.