@@ -43,7 +43,10 @@ public StdWString(string s)
4343 var byteCount = Encoding . Unicode . GetByteCount ( s ) / sizeof ( char ) ;
4444 data = AllocT < char > ( byteCount + 1 ) ;
4545 capacity = size = s . Length ;
46- Encoding . Unicode . GetBytes ( s , new Span < byte > ( data , byteCount * sizeof ( char ) ) ) ;
46+ fixed ( char * chars = s )
47+ {
48+ Encoding . Unicode . GetBytes ( chars , s . Length , ( byte * ) data , byteCount ) ;
49+ }
4750 data [ size ] = '\0 ' ;
4851 }
4952
@@ -863,7 +866,10 @@ public readonly ReadOnlySpan<char> AsReadOnlySpan()
863866 /// <returns><c>true</c> if the two strings are equal; otherwise, <c>false</c>.</returns>
864867 public static bool operator == ( StdWString str1 , string str2 )
865868 {
866- return str1 . Compare ( str2 ) ;
869+ fixed ( char * pStr = str2 )
870+ {
871+ return str1 . Compare ( new ReadOnlySpan < char > ( pStr , str2 . Length ) ) ;
872+ }
867873 }
868874
869875 /// <summary>
@@ -874,7 +880,10 @@ public readonly ReadOnlySpan<char> AsReadOnlySpan()
874880 /// <returns><c>true</c> if the two strings are not equal; otherwise, <c>false</c>.</returns>
875881 public static bool operator != ( StdWString str1 , string str2 )
876882 {
877- return ! str1 . Compare ( str2 ) ;
883+ fixed ( char * pStr = str2 )
884+ {
885+ return ! str1 . Compare ( new ReadOnlySpan < char > ( pStr , str2 . Length ) ) ;
886+ }
878887 }
879888
880889 /// <summary>
@@ -932,7 +941,10 @@ public override bool Equals(object? obj)
932941 }
933942 if ( obj is string str )
934943 {
935- return Compare ( str ) ;
944+ fixed ( char * pStr = str )
945+ {
946+ return Compare ( new ReadOnlySpan < char > ( pStr , str . Length ) ) ;
947+ }
936948 }
937949 return false ;
938950 }
@@ -943,12 +955,21 @@ public override bool Equals(object? obj)
943955 /// <returns>The hash code for the string.</returns>
944956 public override int GetHashCode ( )
945957 {
958+ #if NET5_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
946959 HashCode hashCode = new ( ) ;
947960 for ( int i = 0 ; i < size ; i ++ )
948961 {
949962 hashCode . Add ( data [ i ] ) ;
950963 }
951964 return hashCode . ToHashCode ( ) ;
965+ #else
966+ int hash = 17 ;
967+ for ( int i = 0 ; i < size ; i ++ )
968+ {
969+ hash = hash * 31 + data [ i ] . GetHashCode ( ) ;
970+ }
971+ return hash ;
972+ #endif
952973 }
953974
954975 /// <summary>
0 commit comments