Changeset 125992 in webkit


Ignore:
Timestamp:
Aug 19, 2012 9:03:24 PM (12 years ago)
Author:
benjamin@webkit.org
Message:

Do not allocate SQLiteDatabase's m_openErrorMessage until its needed
https://bugs.webkit.org/show_bug.cgi?id=94434

Reviewed by Andreas Kling.

Previously, m_openErrorMessage was initialized from a static literal string whenever
the database is not open.

This patch changes the way we use m_openErrorMessage to only allocate a string in the
few cases where we need it. If there is no error message, we fallback to the previous
default string.

The goal is to prevent allocating the string unless needed. That saves initialization time
and memory.

  • platform/sql/SQLiteDatabase.cpp:

(WebCore::SQLiteDatabase::SQLiteDatabase):
(WebCore::SQLiteDatabase::close):
(WebCore::SQLiteDatabase::lastErrorMsg):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r125991 r125992  
     12012-08-19  Benjamin Poulain  <benjamin@webkit.org>
     2
     3        Do not allocate SQLiteDatabase's m_openErrorMessage until its needed
     4        https://bugs.webkit.org/show_bug.cgi?id=94434
     5
     6        Reviewed by Andreas Kling.
     7
     8        Previously, m_openErrorMessage was initialized from a static literal string whenever
     9        the database is not open.
     10
     11        This patch changes the way we use m_openErrorMessage to only allocate a string in the
     12        few cases where we need it. If there is no error message, we fallback to the previous
     13        default string.
     14
     15        The goal is to prevent allocating the string unless needed. That saves initialization time
     16        and memory.
     17
     18        * platform/sql/SQLiteDatabase.cpp:
     19        (WebCore::SQLiteDatabase::SQLiteDatabase):
     20        (WebCore::SQLiteDatabase::close):
     21        (WebCore::SQLiteDatabase::lastErrorMsg):
     22
    1232012-08-19  Benjamin Poulain  <benjamin@webkit.org>
    224
  • trunk/Source/WebCore/platform/sql/SQLiteDatabase.cpp

    r108015 r125992  
    5757    , m_interrupted(false)
    5858    , m_openError(SQLITE_ERROR)
    59     , m_openErrorMessage(notOpenErrorMessage)
     59    , m_openErrorMessage()
    6060{
    6161}
     
    115115    m_openingThread = 0;
    116116    m_openError = SQLITE_ERROR;
    117     m_openErrorMessage = notOpenErrorMessage;
     117    m_openErrorMessage = CString();
    118118}
    119119
     
    334334
    335335const char* SQLiteDatabase::lastErrorMsg()
    336 {
    337     return m_db ? sqlite3_errmsg(m_db) : m_openErrorMessage.data();
     336{
     337    if (m_db)
     338        return sqlite3_errmsg(m_db);
     339    return m_openErrorMessage.isNull() ? notOpenErrorMessage : m_openErrorMessage.data();
    338340}
    339341
Note: See TracChangeset for help on using the changeset viewer.