diff options
| author | Jeff Sharkey <jsharkey@android.com> | 2020-10-17 21:12:12 -0600 |
|---|---|---|
| committer | Jeff Sharkey <jsharkey@android.com> | 2020-10-20 22:00:18 -0600 |
| commit | f18719bb73298a931752d7b3c0aa478642859aef (patch) | |
| tree | e24be822a34e43ecc70700d8273af82e668eaede /core/java/android/database/sqlite | |
| parent | 1c08f4825334622ee90331372f68319feb2fa68d (diff) | |
Apply fixes for EfficientStrings.
Refactoring to avoid paying the cost of extra StringBuilder that are
quickly disposed.
Bug: 170978902
Test: none
Exempt-From-Owner-Approval: trivial refactoring
Change-Id: Icd914a63cdadf8123c1e5a5073f85245f0791f0b
Diffstat (limited to 'core/java/android/database/sqlite')
| -rw-r--r-- | core/java/android/database/sqlite/SQLiteConnection.java | 32 | ||||
| -rw-r--r-- | core/java/android/database/sqlite/SQLiteDatabase.java | 2 |
2 files changed, 19 insertions, 15 deletions
diff --git a/core/java/android/database/sqlite/SQLiteConnection.java b/core/java/android/database/sqlite/SQLiteConnection.java index 2f67f6ddc082..865940e796c8 100644 --- a/core/java/android/database/sqlite/SQLiteConnection.java +++ b/core/java/android/database/sqlite/SQLiteConnection.java @@ -226,7 +226,8 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen NoPreloadHolder.DEBUG_SQL_STATEMENTS, NoPreloadHolder.DEBUG_SQL_TIME, mConfiguration.lookasideSlotSize, mConfiguration.lookasideSlotCount); } catch (SQLiteCantOpenDatabaseException e) { - String message = String.format("Cannot open database '%s'", file); + final StringBuilder message = new StringBuilder("Cannot open database '") + .append(file).append('\''); try { // Try to diagnose for common reasons. If something fails in here, that's fine; @@ -236,20 +237,21 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen final Path dir = path.getParent(); if (!Files.isDirectory(dir)) { - message += ": Directory " + dir + " doesn't exist"; + message.append(": Directory ").append(dir).append(" doesn't exist"); } else if (!Files.exists(path)) { - message += ": File " + path + " doesn't exist"; + message.append(": File ").append(path).append(" doesn't exist"); } else if (!Files.isReadable(path)) { - message += ": File " + path + " is not readable"; + message.append(": File ").append(path).append(" is not readable"); } else if (Files.isDirectory(path)) { - message += ": Path " + path + " is a directory"; + message.append(": Path ").append(path).append(" is a directory"); } else { - message += ": Unknown reason"; + message.append(": Unknown reason"); } } catch (Throwable th) { - message += ": Unknown reason; cannot examine filesystem: " + th.getMessage(); + message.append(": Unknown reason; cannot examine filesystem: ") + .append(th.getMessage()); } - throw new SQLiteCantOpenDatabaseException(message, e); + throw new SQLiteCantOpenDatabaseException(message.toString(), e); } finally { mRecentOperations.endOperation(cookie); } @@ -1293,11 +1295,11 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen } catch (SQLiteException ex) { // Ignore. } - String label = " (attached) " + name; + StringBuilder label = new StringBuilder(" (attached) ").append(name); if (!path.isEmpty()) { - label += ": " + path; + label.append(": ").append(path); } - dbStatsList.add(new DbStats(label, pageCount, pageSize, 0, 0, 0, 0)); + dbStatsList.add(new DbStats(label.toString(), pageCount, pageSize, 0, 0, 0, 0)); } } catch (SQLiteException ex) { // Ignore. @@ -1319,9 +1321,11 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen private DbStats getMainDbStatsUnsafe(int lookaside, long pageCount, long pageSize) { // The prepared statement cache is thread-safe so we can access its statistics // even if we do not own the database connection. - String label = mConfiguration.path; - if (!mIsPrimaryConnection) { - label += " (" + mConnectionId + ")"; + String label; + if (mIsPrimaryConnection) { + label = mConfiguration.path; + } else { + label = mConfiguration.path + " (" + mConnectionId + ")"; } return new DbStats(label, pageCount, pageSize, lookaside, mPreparedStatementCache.hitCount(), diff --git a/core/java/android/database/sqlite/SQLiteDatabase.java b/core/java/android/database/sqlite/SQLiteDatabase.java index 837f30efc35f..a2cbdd3829ff 100644 --- a/core/java/android/database/sqlite/SQLiteDatabase.java +++ b/core/java/android/database/sqlite/SQLiteDatabase.java @@ -1692,7 +1692,7 @@ public final class SQLiteDatabase extends SQLiteClosable { sql.append((i > 0) ? ",?" : "?"); } } else { - sql.append(nullColumnHack + ") VALUES (NULL"); + sql.append(nullColumnHack).append(") VALUES (NULL"); } sql.append(')'); |
