@@ -78,22 +78,13 @@ export class Id {
7878
7979 let result : string = this . replace_invalid_chars ( name ) ;
8080
81- const sorted_tags : { [ k : string ] : string } = Object . fromEntries ( Object . entries ( tags ) . sort (
82- ( a : [ string , string ] , b : [ string , string ] ) : number => {
83- const kSort : number = a [ 0 ] . localeCompare ( b [ 0 ] ) ;
84- if ( kSort != 0 ) {
85- return kSort ;
86- } else {
87- return a [ 1 ] . localeCompare ( b [ 1 ] ) ;
88- }
89- }
90- ) ) ;
91-
92- Object . entries ( sorted_tags ) . forEach ( ( [ k , v ] : [ string , string ] ) : void => {
93- k = this . replace_invalid_chars ( k ) ;
94- v = this . replace_invalid_chars ( v ) ;
95- result += `,${ k } =${ v } ` ;
96- } ) ;
81+ const sorted_entries = Object . entries ( tags ) . sort (
82+ ( a , b ) => a [ 0 ] . localeCompare ( b [ 0 ] ) || a [ 1 ] . localeCompare ( b [ 1 ] )
83+ ) ;
84+
85+ for ( const [ k , v ] of sorted_entries ) {
86+ result += `,${ this . replace_invalid_chars ( k ) } =${ this . replace_invalid_chars ( v ) } ` ;
87+ }
9788
9889 return result ;
9990 }
@@ -103,20 +94,19 @@ export class Id {
10394 }
10495
10596 tags ( ) : Tags {
106- return structuredClone ( this . _tags ) ;
97+ return { ... this . _tags } ;
10798 }
10899
109100 with_tag ( k : string , v : string ) : Id {
110- const new_tags : Tags = structuredClone ( this . _tags ) ;
111- new_tags [ k ] = v ;
101+ const new_tags : Tags = { ...this . _tags , [ k ] : v } ;
112102 return new Id ( this . _name , new_tags ) ;
113103 }
114104
115105 with_tags ( tags : Tags ) : Id {
116106 if ( Object . keys ( tags ) . length == 0 ) {
117107 return this ;
118108 }
119- const new_tags = { ...structuredClone ( this . _tags ) , ...tags } ;
109+ const new_tags = { ...this . _tags , ...tags } ;
120110 return new Id ( this . _name , new_tags ) ;
121111 }
122112
0 commit comments