File tree Expand file tree Collapse file tree 3 files changed +10
-15
lines changed Expand file tree Collapse file tree 3 files changed +10
-15
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ import { Integer } from '@firebase/webchannel-wrapper/bloom-blob';
19
19
20
20
import { debugAssert , fail } from '../util/assert' ;
21
21
import { Code , FirestoreError } from '../util/error' ;
22
- import { primitiveComparator , compareUtf8Strings } from '../util/misc' ;
22
+ import { primitiveComparator , compareUtf16Strings } from '../util/misc' ;
23
23
24
24
export const DOCUMENT_KEY_NAME = '__name__' ;
25
25
@@ -202,7 +202,7 @@ abstract class BasePath<B extends BasePath<B>> {
202
202
) ;
203
203
} else {
204
204
// both non-numeric
205
- return compareUtf8Strings ( lhs , rhs ) ;
205
+ return compareUtf16Strings ( lhs , rhs ) ;
206
206
}
207
207
}
208
208
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ import { fail } from '../util/assert';
28
28
import {
29
29
arrayEquals ,
30
30
primitiveComparator ,
31
- compareUtf8Strings
31
+ compareUtf16Strings
32
32
} from '../util/misc' ;
33
33
import { forEach , objectSize } from '../util/obj' ;
34
34
import { isNegativeZero } from '../util/types' ;
@@ -255,7 +255,7 @@ export function valueCompare(left: Value, right: Value): number {
255
255
getLocalWriteTime ( right )
256
256
) ;
257
257
case TypeOrder . StringValue :
258
- return compareUtf8Strings ( left . stringValue ! , right . stringValue ! ) ;
258
+ return compareUtf16Strings ( left . stringValue ! , right . stringValue ! ) ;
259
259
case TypeOrder . BlobValue :
260
260
return compareBlobs ( left . bytesValue ! , right . bytesValue ! ) ;
261
261
case TypeOrder . RefValue :
@@ -404,7 +404,7 @@ function compareMaps(left: MapValue, right: MapValue): number {
404
404
rightKeys . sort ( ) ;
405
405
406
406
for ( let i = 0 ; i < leftKeys . length && i < rightKeys . length ; ++ i ) {
407
- const keyCompare = compareUtf8Strings ( leftKeys [ i ] , rightKeys [ i ] ) ;
407
+ const keyCompare = compareUtf16Strings ( leftKeys [ i ] , rightKeys [ i ] ) ;
408
408
if ( keyCompare !== 0 ) {
409
409
return keyCompare ;
410
410
}
Original file line number Diff line number Diff line change @@ -75,20 +75,15 @@ export interface Equatable<T> {
75
75
isEqual ( other : T ) : boolean ;
76
76
}
77
77
78
- /** Compare strings in UTF-8 encoded byte order */
79
- export function compareUtf8Strings ( left : string , right : string ) : number {
80
- // Convert the string to UTF-8 encoded bytes
81
- const encodedLeft = newTextEncoder ( ) . encode ( left ) ;
82
- const encodedRight = newTextEncoder ( ) . encode ( right ) ;
83
-
84
- for ( let i = 0 ; i < Math . min ( encodedLeft . length , encodedRight . length ) ; i ++ ) {
85
- const comparison = primitiveComparator ( encodedLeft [ i ] , encodedRight [ i ] ) ;
78
+ /** Compare strings in UTF-16 encoded byte order */
79
+ export function compareUtf16Strings ( left : string , right : string ) : number {
80
+ for ( let i = 0 ; i < Math . min ( left . length , right . length ) ; i ++ ) {
81
+ const comparison = primitiveComparator ( left . charCodeAt ( i ) , right . charCodeAt ( i ) ) ;
86
82
if ( comparison !== 0 ) {
87
83
return comparison ;
88
84
}
89
85
}
90
-
91
- return primitiveComparator ( encodedLeft . length , encodedRight . length ) ;
86
+ return primitiveComparator ( left . length , right . length ) ;
92
87
}
93
88
94
89
export interface Iterable < V > {
You can’t perform that action at this time.
0 commit comments