@@ -490,7 +490,7 @@ private void BuildEnumParsers(
490490 }
491491 else
492492 {
493- NewLine ( ) . Append ( "global::RESPite.AsciiHash.Hash(" ) . Append ( method . From . Name ) . Append ( ", out var hashCS, out var hashCI );" ) ;
493+ NewLine ( ) . Append ( "global::RESPite.AsciiHash.Hash(" ) . Append ( method . From . Name ) . Append ( ", out var hashCS, out var hashUC );" ) ;
494494 }
495495
496496 if ( string . IsNullOrEmpty ( method . CaseSensitive . Name ) )
@@ -544,68 +544,36 @@ void Write(bool caseSensitive)
544544 . ThenBy ( x => x . ParseText ) )
545545 {
546546 var len = member . ParseText . Length ;
547- AsciiHash . Hash ( member . ParseText , out var hashCS , out var hashCI ) ;
547+ AsciiHash . Hash ( member . ParseText , out var hashCS , out var hashUC ) ;
548548
549549 bool valueCaseSensitive = caseSensitive || ! HasCaseSensitiveCharacters ( member . ParseText ) ;
550550
551551 line = NewLine ( ) . Append ( len ) ;
552552 if ( valueCaseSensitive )
553553 {
554554 line . Append ( " when hashCS is " ) . Append ( hashCS ) ;
555- if ( len > AsciiHash . MaxBytesHashIsEqualityCS )
556- {
557- line . Append ( " && " ) ;
558- WriteValueTest ( member . ParseText , true ) ;
559- }
560555 }
561556 else
562557 {
563- // optimize for "all_lower" or "ALL_UPPER" matches; "Mixed_Match" comes last
564- var ucText = member . ParseText . ToUpperInvariant ( ) ;
565- var lcText = member . ParseText . ToLowerInvariant ( ) ;
566- long hashUC = AsciiHash . HashCS ( ucText ) , hashLC = AsciiHash . HashCS ( lcText ) ;
567-
568- if ( len <= AsciiHash . MaxBytesHashIsEqualityCS )
569- {
570- // note we know the lc and uc hash must be different
571- line . Append ( " when (hashCS is " ) . Append ( hashUC ) . Append ( " or " ) . Append ( hashLC )
572- . Append ( ") || (hashCI is " ) . Append ( hashCI ) . Append ( " && " ) ;
573- WriteValueTest ( member . ParseText , false ) ;
574- line . Append ( ")" ) ;
575- }
576- else if ( hashLC == hashCS && hashUC == hashCS )
577- {
578- // there are alphas, but not in the hashed portion
579- line . Append ( " when hashCS is " ) . Append ( hashLC ) . Append ( " && " ) ;
580- WriteValueTest ( member . ParseText , false ) ;
581- }
582- else
583- {
584- line . Append ( " when (hashCS is " ) . Append ( hashLC ) . Append ( " && " ) ;
585- WriteValueTest ( lcText , true ) ;
586- line . Append ( ") || (hashCS is " ) . Append ( hashUC ) . Append ( " && " ) ;
587- WriteValueTest ( ucText , true ) ;
588- line . Append ( ") || (hashCI is " ) . Append ( hashCI ) . Append ( " && " ) ;
589- WriteValueTest ( member . ParseText , false ) ;
590- line . Append ( ")" ) ;
591- }
558+ line . Append ( " when hashUC is " ) . Append ( hashUC ) ;
592559 }
593- line . Append ( " => " ) . Append ( method . To . Type ) . Append ( "." ) . Append ( member . EnumMember ) . Append ( "," ) ;
594-
595- void WriteValueTest ( string value , bool testCS )
560+ if ( len > AsciiHash . MaxBytesHashed )
596561 {
562+ line . Append ( " && " ) ;
597563 var csValue = SyntaxFactory
598564 . LiteralExpression (
599565 SyntaxKind . StringLiteralExpression ,
600- SyntaxFactory . Literal ( value ) )
566+ SyntaxFactory . Literal ( member . ParseText ) )
601567 . ToFullString ( ) ;
602568
603569 line . Append ( "global::RESPite.AsciiHash." )
604- . Append ( testCS ? nameof ( AsciiHash . SequenceEqualsCS ) : nameof ( AsciiHash . SequenceEqualsCI ) )
570+ . Append ( valueCaseSensitive ? nameof ( AsciiHash . SequenceEqualsCS ) : nameof ( AsciiHash . SequenceEqualsCI ) )
605571 . Append ( "(" ) . Append ( method . From . Name ) . Append ( ", " ) . Append ( csValue ) ;
606572 if ( method . From . IsBytes ) line . Append ( "u8" ) ;
607573 line . Append ( ")" ) ;
608574 }
575+
576+ line . Append ( " => " ) . Append ( method . To . Type ) . Append ( "." ) . Append ( member . EnumMember ) . Append ( "," ) ;
609577 }
610578
611579 NewLine ( ) . Append ( "_ => (" ) . Append ( method . To . Type ) . Append ( ")" ) . Append ( method . DefaultValue )
@@ -717,29 +685,29 @@ private static void BuildTypeImplementations(
717685 . LiteralExpression ( SyntaxKind . StringLiteralExpression , SyntaxFactory . Literal ( literal . Value ) )
718686 . ToFullString ( ) ;
719687
720- AsciiHash . Hash ( literal . Value , out var hashCS , out var hashCI ) ;
688+ AsciiHash . Hash ( literal . Value , out var hashCS , out var hashUC ) ;
721689 NewLine ( ) . Append ( "static partial class " ) . Append ( literal . Name ) ;
722690 NewLine ( ) . Append ( "{" ) ;
723691 indent ++ ;
724692 NewLine ( ) . Append ( "public const int Length = " ) . Append ( literal . Value . Length ) . Append ( ';' ) ;
725693 NewLine ( ) . Append ( "public const long HashCS = " ) . Append ( hashCS ) . Append ( ';' ) ;
726- NewLine ( ) . Append ( "public const long HashCI = " ) . Append ( hashCI ) . Append ( ';' ) ;
694+ NewLine ( ) . Append ( "public const long HashUC = " ) . Append ( hashUC ) . Append ( ';' ) ;
727695 NewLine ( ) . Append ( "public static ReadOnlySpan<byte> U8 => " ) . Append ( csValue ) . Append ( "u8;" ) ;
728696 NewLine ( ) . Append ( "public const string Text = " ) . Append ( csValue ) . Append ( ';' ) ;
729- if ( literal . Value . Length <= AsciiHash . MaxBytesHashIsEqualityCS )
697+ if ( literal . Value . Length <= AsciiHash . MaxBytesHashed )
730698 {
731699 // the case-sensitive hash enforces all the values
732700 NewLine ( ) . Append (
733- "public static bool IsCS(long hash, ReadOnlySpan<byte> value) => hash == HashCS & value.Length == Length;" ) ;
701+ "public static bool IsCS(ReadOnlySpan<byte> value, long cs ) => cs == HashCS & value.Length == Length;" ) ;
734702 NewLine ( ) . Append (
735- "public static bool IsCI(long hash, ReadOnlySpan<byte> value) => (hash == HashCI & value.Length == Length) && (global::RESPite.AsciiHash.HashCS(value) == HashCS || global::RESPite.AsciiHash.EqualsCI(value, U8)) ;" ) ;
703+ "public static bool IsCI(ReadOnlySpan<byte> value, long uc ) => uc == HashUC & value.Length == Length;" ) ;
736704 }
737705 else
738706 {
739707 NewLine ( ) . Append (
740- "public static bool IsCS(long hash, ReadOnlySpan<byte> value) => hash == HashCS && value.SequenceEqual(U8);" ) ;
708+ "public static bool IsCS(ReadOnlySpan<byte> value, long cs ) => cs == HashCS && value.SequenceEqual(U8);" ) ;
741709 NewLine ( ) . Append (
742- "public static bool IsCI(long hash, ReadOnlySpan<byte> value) => (hash == HashCI & value.Length == Length) && global::RESPite.AsciiHash.EqualsCI (value, U8);" ) ;
710+ "public static bool IsCI(ReadOnlySpan<byte> value, long uc ) => uc == HashUC && global::RESPite.AsciiHash.SequenceEqualsCI (value, U8);" ) ;
743711 }
744712
745713 indent -- ;
0 commit comments