summaryrefslogtreecommitdiffstats
path: root/core/java/android/database
diff options
context:
space:
mode:
authorAndreas Gampe <agampe@google.com>2015-04-22 00:23:51 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-04-22 00:23:51 +0000
commit0db3cdc59aaf208c53747889b13c023a99a2dc7b (patch)
treed51b346431b10f40a15176f4b0469aee77a21ffd /core/java/android/database
parent7651dec5c916f7f69e4a65443d29912248cb5418 (diff)
parent5b0c0964d843319b1b89767cd3d3f1daa984df51 (diff)
downloadframeworks_base-0db3cdc59aaf208c53747889b13c023a99a2dc7b.zip
frameworks_base-0db3cdc59aaf208c53747889b13c023a99a2dc7b.tar.gz
frameworks_base-0db3cdc59aaf208c53747889b13c023a99a2dc7b.tar.bz2
am 5b0c0964: am fb861b6c: am 31fb202e: Merge "Frameworks/base: Compile-time optimize SQLiteConnection"
* commit '5b0c0964d843319b1b89767cd3d3f1daa984df51': Frameworks/base: Compile-time optimize SQLiteConnection
Diffstat (limited to 'core/java/android/database')
-rw-r--r--core/java/android/database/sqlite/SQLiteConnection.java17
1 files changed, 10 insertions, 7 deletions
diff --git a/core/java/android/database/sqlite/SQLiteConnection.java b/core/java/android/database/sqlite/SQLiteConnection.java
index 24a7d33..3cda39a 100644
--- a/core/java/android/database/sqlite/SQLiteConnection.java
+++ b/core/java/android/database/sqlite/SQLiteConnection.java
@@ -91,8 +91,6 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
private static final String[] EMPTY_STRING_ARRAY = new String[0];
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
- private static final Pattern TRIM_SQL_PATTERN = Pattern.compile("[\\s]*\\n+[\\s]*");
-
private final CloseGuard mCloseGuard = CloseGuard.get();
private final SQLiteConnectionPool mPool;
@@ -1203,7 +1201,11 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
}
private static String trimSqlForDisplay(String sql) {
- return TRIM_SQL_PATTERN.matcher(sql).replaceAll(" ");
+ // Note: Creating and caching a regular expression is expensive at preload-time
+ // and stops compile-time initialization. This pattern is only used when
+ // dumping the connection, which is a rare (mainly error) case. So:
+ // DO NOT CACHE.
+ return sql.replaceAll("[\\s]*\\n+[\\s]*", " ");
}
/**
@@ -1437,9 +1439,6 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
}
private static final class Operation {
- private static final SimpleDateFormat sDateFormat =
- new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
-
public long mStartTime;
public long mEndTime;
public String mKind;
@@ -1494,7 +1493,11 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
}
private String getFormattedStartTime() {
- return sDateFormat.format(new Date(mStartTime));
+ // Note: SimpleDateFormat is not thread-safe, cannot be compile-time created, and is
+ // relatively expensive to create during preloading. This method is only used
+ // when dumping a connection, which is a rare (mainly error) case. So:
+ // DO NOT CACHE.
+ return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date(mStartTime));
}
}
}