@@ -121,6 +121,20 @@ function defineLazyGetters(object, getterDefObj, stats) {
121
121
return object
122
122
}
123
123
124
+ let _localeCompare
125
+ /*@__NO_SIDE_EFFECTS__ */
126
+ function entryKeyComparator ( a , b ) {
127
+ if ( _localeCompare === undefined ) {
128
+ const sorts = /*@__PURE__ */ require ( './sorts' )
129
+ _localeCompare = sorts . localeCompare
130
+ }
131
+ const keyA = a [ 0 ]
132
+ const keyB = b [ 0 ]
133
+ const strKeyA = typeof keyA === 'string' ? keyA : String ( keyA )
134
+ const strKeyB = typeof keyB === 'string' ? keyB : String ( keyB )
135
+ return _localeCompare ( strKeyA , strKeyB )
136
+ }
137
+
124
138
/*@__NO_SIDE_EFFECTS__ */
125
139
function getOwnPropertyValues ( obj ) {
126
140
if ( obj === null || obj === undefined ) {
@@ -251,25 +265,23 @@ function toSortedObject(obj) {
251
265
252
266
/*@__NO_SIDE_EFFECTS__ */
253
267
function toSortedObjectFromEntries ( entries ) {
254
- const { length } = entries
255
- if ( ! length ) {
256
- return { }
257
- }
258
- const stringEntries = [ ]
268
+ const otherEntries = [ ]
259
269
const symbolEntries = [ ]
260
- for ( let i = 0 ; i < length ; i += 1 ) {
261
- const entry = entries [ i ]
270
+ // Use for-of to work with entries iterators.
271
+ for ( const entry of entries ) {
262
272
if ( typeof entry [ 0 ] === 'symbol' ) {
263
273
symbolEntries . push ( entry )
264
274
} else {
265
- stringEntries . push ( entry )
275
+ otherEntries . push ( entry )
266
276
}
267
277
}
268
- const { localeCompare } = /*@__PURE__ */ require ( './sorts' )
278
+ if ( ! otherEntries . length && ! symbolEntries . length ) {
279
+ return [ ]
280
+ }
269
281
return ObjectFromEntries ( [
270
282
// The String constructor is safe to use with symbols.
271
- ...symbolEntries . sort ( ( a , b ) => localeCompare ( String ( a [ 0 ] ) , String ( b [ 0 ] ) ) ) ,
272
- ...stringEntries . sort ( ( a , b ) => localeCompare ( a [ 0 ] , b [ 0 ] ) )
283
+ ...symbolEntries . sort ( entryKeyComparator ) ,
284
+ ...otherEntries . sort ( entryKeyComparator )
273
285
] )
274
286
}
275
287
0 commit comments