System.Data.SQLite
Check-in [32ce066699]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Reduce the number of String.Compare calls in the hot path for SQLiteCommand.ExecuteReader.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 32ce06669970e8027420d7b969a9ed1e6c36b86a
User & Date: mistachkin 2011-09-24 07:41:37
Context
2011-09-24
08:09
Fix optimized DbType lookup for database type names that contain parenthesis. check-in: 9d9fa54984 user: mistachkin tags: trunk
07:41
Reduce the number of String.Compare calls in the hot path for SQLiteCommand.ExecuteReader. check-in: 32ce066699 user: mistachkin tags: trunk
2011-09-23
19:32
Rename the 'enumerableToString' test suite helper procedure to the more correct 'enumerableToList'. check-in: 4194bc2cb4 user: mistachkin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to System.Data.SQLite/SQLiteConvert.cs.

649
650
651
652
653
654
655
656
657
658
659
660

661
662
663
664
665
666

667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711















712
713
714
715
716
717
718
...
867
868
869
870
871
872
873
874































    /// </summary>
    /// <param name="Name">The name of the type to match</param>
    /// <returns>The .NET DBType the text evaluates to.</returns>
    internal static DbType TypeNameToDbType(string Name)
    {
      if (String.IsNullOrEmpty(Name)) return DbType.Object;

      int x = _typeNames.Length;
      for (int n = 0; n < x; n++)
      {
        if (String.Compare(Name, 0, _typeNames[n].typeName, 0, _typeNames[n].typeName.Length, StringComparison.OrdinalIgnoreCase) == 0)
          return _typeNames[n].dataType; 

      }
      return DbType.Object;
    }
    #endregion

    private static SQLiteTypeNames[] _typeNames = {

      new SQLiteTypeNames("COUNTER", DbType.Int64),
      new SQLiteTypeNames("AUTOINCREMENT", DbType.Int64),
      new SQLiteTypeNames("IDENTITY", DbType.Int64),
      new SQLiteTypeNames("LONGTEXT", DbType.String),
      new SQLiteTypeNames("LONGCHAR", DbType.String),
      new SQLiteTypeNames("LONGVARCHAR", DbType.String),
      new SQLiteTypeNames("LONG", DbType.Int64),
      new SQLiteTypeNames("TINYINT", DbType.Byte),
      new SQLiteTypeNames("INTEGER", DbType.Int64),
      new SQLiteTypeNames("INT", DbType.Int32),
      new SQLiteTypeNames("VARCHAR", DbType.String),
      new SQLiteTypeNames("NVARCHAR", DbType.String),
      new SQLiteTypeNames("CHAR", DbType.String),
      new SQLiteTypeNames("NCHAR", DbType.String),
      new SQLiteTypeNames("TEXT", DbType.String),
      new SQLiteTypeNames("NTEXT", DbType.String),
      new SQLiteTypeNames("STRING", DbType.String),
      new SQLiteTypeNames("DOUBLE", DbType.Double),
      new SQLiteTypeNames("FLOAT", DbType.Double),
      new SQLiteTypeNames("REAL", DbType.Double),
      new SQLiteTypeNames("BIT", DbType.Boolean),
      new SQLiteTypeNames("YESNO", DbType.Boolean),
      new SQLiteTypeNames("LOGICAL", DbType.Boolean),
      new SQLiteTypeNames("BOOL", DbType.Boolean),
      new SQLiteTypeNames("NUMERIC", DbType.Decimal),
      new SQLiteTypeNames("DECIMAL", DbType.Decimal),
      new SQLiteTypeNames("MONEY", DbType.Decimal),
      new SQLiteTypeNames("CURRENCY", DbType.Decimal),
      new SQLiteTypeNames("TIME", DbType.DateTime),
      new SQLiteTypeNames("DATE", DbType.DateTime),
      new SQLiteTypeNames("DATETIME", DbType.DateTime),
      new SQLiteTypeNames("SMALLDATE", DbType.DateTime),
      new SQLiteTypeNames("BLOB", DbType.Binary),
      new SQLiteTypeNames("BINARY", DbType.Binary),
      new SQLiteTypeNames("VARBINARY", DbType.Binary),
      new SQLiteTypeNames("IMAGE", DbType.Binary),
      new SQLiteTypeNames("GENERAL", DbType.Binary),
      new SQLiteTypeNames("OLEOBJECT", DbType.Binary),
      new SQLiteTypeNames("GUID", DbType.Guid),
      new SQLiteTypeNames("UNIQUEIDENTIFIER", DbType.Guid),
      new SQLiteTypeNames("MEMO", DbType.String),
      new SQLiteTypeNames("NOTE", DbType.String),
      new SQLiteTypeNames("SMALLINT", DbType.Int16),
      new SQLiteTypeNames("BIGINT", DbType.Int64),
    };















  }

  /// <summary>
  /// SQLite has very limited types, and is inherently text-based.  The first 5 types below represent the sum of all types SQLite
  /// understands.  The DateTime extension to the spec is for internal use only.
  /// </summary>
  public enum TypeAffinity
................................................................................
      typeName = newtypeName;
      dataType = newdataType;
    }

    internal string typeName;
    internal DbType dataType;
  }
}






































|
<

<
<
>
|
<
<
<
<
<
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
649
650
651
652
653
654
655
656

657


658
659





660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
...
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
    /// </summary>
    /// <param name="Name">The name of the type to match</param>
    /// <returns>The .NET DBType the text evaluates to.</returns>
    internal static DbType TypeNameToDbType(string Name)
    {
      if (String.IsNullOrEmpty(Name)) return DbType.Object;

      if (_typeNames == null)

      {


        _typeNames = new Dictionary<string, SQLiteTypeNames>(new TypeNameStringComparer());






        foreach (SQLiteTypeNames typeName in new SQLiteTypeNames[] {
            new SQLiteTypeNames("COUNTER", DbType.Int64),
            new SQLiteTypeNames("AUTOINCREMENT", DbType.Int64),
            new SQLiteTypeNames("IDENTITY", DbType.Int64),
            new SQLiteTypeNames("LONGTEXT", DbType.String),
            new SQLiteTypeNames("LONGCHAR", DbType.String),
            new SQLiteTypeNames("LONGVARCHAR", DbType.String),
            new SQLiteTypeNames("LONG", DbType.Int64),
            new SQLiteTypeNames("TINYINT", DbType.Byte),
            new SQLiteTypeNames("INTEGER", DbType.Int64),
            new SQLiteTypeNames("INT", DbType.Int32),
            new SQLiteTypeNames("VARCHAR", DbType.String),
            new SQLiteTypeNames("NVARCHAR", DbType.String),
            new SQLiteTypeNames("CHAR", DbType.String),
            new SQLiteTypeNames("NCHAR", DbType.String),
            new SQLiteTypeNames("TEXT", DbType.String),
            new SQLiteTypeNames("NTEXT", DbType.String),
            new SQLiteTypeNames("STRING", DbType.String),
            new SQLiteTypeNames("DOUBLE", DbType.Double),
            new SQLiteTypeNames("FLOAT", DbType.Double),
            new SQLiteTypeNames("REAL", DbType.Double),
            new SQLiteTypeNames("BIT", DbType.Boolean),
            new SQLiteTypeNames("YESNO", DbType.Boolean),
            new SQLiteTypeNames("LOGICAL", DbType.Boolean),
            new SQLiteTypeNames("BOOL", DbType.Boolean),
            new SQLiteTypeNames("NUMERIC", DbType.Decimal),
            new SQLiteTypeNames("DECIMAL", DbType.Decimal),
            new SQLiteTypeNames("MONEY", DbType.Decimal),
            new SQLiteTypeNames("CURRENCY", DbType.Decimal),
            new SQLiteTypeNames("TIME", DbType.DateTime),
            new SQLiteTypeNames("DATE", DbType.DateTime),
            new SQLiteTypeNames("DATETIME", DbType.DateTime),
            new SQLiteTypeNames("SMALLDATE", DbType.DateTime),
            new SQLiteTypeNames("BLOB", DbType.Binary),
            new SQLiteTypeNames("BINARY", DbType.Binary),
            new SQLiteTypeNames("VARBINARY", DbType.Binary),
            new SQLiteTypeNames("IMAGE", DbType.Binary),
            new SQLiteTypeNames("GENERAL", DbType.Binary),
            new SQLiteTypeNames("OLEOBJECT", DbType.Binary),
            new SQLiteTypeNames("GUID", DbType.Guid),
            new SQLiteTypeNames("UNIQUEIDENTIFIER", DbType.Guid),
            new SQLiteTypeNames("MEMO", DbType.String),
            new SQLiteTypeNames("NOTE", DbType.String),
            new SQLiteTypeNames("SMALLINT", DbType.Int16),
            new SQLiteTypeNames("BIGINT", DbType.Int64)
          })
          {
            _typeNames.Add(typeName.typeName, typeName);
          }
      }

      SQLiteTypeNames value;

      if (_typeNames.TryGetValue(Name, out value))
        return value.dataType;

      return DbType.Object;
    }
    #endregion

    private static Dictionary<string, SQLiteTypeNames> _typeNames = null;
  }

  /// <summary>
  /// SQLite has very limited types, and is inherently text-based.  The first 5 types below represent the sum of all types SQLite
  /// understands.  The DateTime extension to the spec is for internal use only.
  /// </summary>
  public enum TypeAffinity
................................................................................
      typeName = newtypeName;
      dataType = newdataType;
    }

    internal string typeName;
    internal DbType dataType;
  }

  internal class TypeNameStringComparer : IEqualityComparer<string>
  {
    #region IEqualityComparer<string> Members
    public bool Equals(
      string left,
      string right
      )
    {
      return String.Equals(left, right, StringComparison.OrdinalIgnoreCase);
    }

    ///////////////////////////////////////////////////////////////////////////

    public int GetHashCode(
      string value
      )
    {
      //
      // NOTE: The only thing that we must guarantee here, according
      //       to the MSDN documentation for IEqualityComparer, is 
      //       that for two given strings, if Equals return true then 
      //       the two strings must hash to the same value.
      //
      if (value != null)
        return value.ToLowerInvariant().GetHashCode();
      else
        throw new ArgumentNullException("value");
    }
    #endregion
  }
}