Hi Joe,

I have couple of small perf tips.

1) SQLite3.GetValue(SqliteStatement stmt, int index, SQLiteType typ)

Starts with this code:
    if (IsNull(stmt, index)) return DBNull.Value;

In my opinion the call into native code (IsNull) is unnecessary in case
typ.Affinity is known - which happens always right now.

2) SqliteDataReader.GetOrdinal()

Column name cache introduced in one of the latest updates is an extremally
powerful optimization, however it could perform even slightly better if all
tested column names were cached.

Below is the code I am using. (Note that caching of invalid column names is
not needed in this case.)

    private int _fieldIndexesLastIndex;
    public override int GetOrdinal(string name)
    {
      CheckClosed();

      // Check if the column name cache has been initialized yet. If not, do
it now.
      if (_fieldIndexes == null)
      {
          _fieldIndexes = new Dictionary<string, int>(new
ColumnNameComparer());
          _fieldIndexesLastIndex = -1;
      }

      // See if the index for the requested column name has been cached
already.
      int r;
      if (!_fieldIndexes.TryGetValue(name, out r))
      {
         // Not yet ... check remaining columns while updating name cache.
         r = -1;
         int nColumns = _activeStatement._sql.ColumnCount(_activeStatement);

         for (int j = _fieldIndexesLastIndex+1; j < nColumns; j++)
         {
            string jname =
_activeStatement._sql.ColumnName(_activeStatement, j);
            _fieldIndexesLastIndex = j;
            _fieldIndexes.Add(jname, j);
            if (String.Compare(name, jname,
StringComparison.OrdinalIgnoreCase) == 0)
            {
              r = j;
              break;
             }
          }
      }

      return r;
    }

Best regards,
  Jan Slodicka



--
View this message in context: 
http://sqlite.1065341.n5.nabble.com/System-Data-SQLite-version-1-0-89-0-released-tp71904p72586.html
Sent from the SQLite mailing list archive at Nabble.com.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to