@@ -12,7 +12,17 @@ namespace NetworkTables
12
12
{
13
13
internal partial class Storage
14
14
{
15
- private bool GetPersistentEntries ( bool periodic , List < StoragePair > entries )
15
+ private class StoragePairComparer : IComparer < ( string key , Value value ) >
16
+ {
17
+ public int Compare ( ( string key , Value value ) x , ( string key , Value value ) y )
18
+ {
19
+ return string . Compare ( x . key , y . key , StringComparison . Ordinal ) ;
20
+ }
21
+ }
22
+
23
+ private readonly static StoragePairComparer s_storageComparer = new StoragePairComparer ( ) ;
24
+
25
+ private bool GetPersistentEntries ( bool periodic , List < ( string key , Value value ) > entries )
16
26
{
17
27
using ( m_monitor . Enter ( ) )
18
28
{
@@ -22,19 +32,19 @@ private bool GetPersistentEntries(bool periodic, List<StoragePair> entries)
22
32
{
23
33
Entry entry = i . Value ;
24
34
if ( ! entry . IsPersistent ( ) ) continue ;
25
- entries . Add ( new StoragePair ( i . Key , entry . Value ) ) ;
35
+ entries . Add ( ( i . Key , entry . Value ) ) ;
26
36
}
27
37
}
28
- entries . Sort ( ) ;
38
+ entries . Sort ( s_storageComparer ) ;
29
39
return true ;
30
40
}
31
41
32
- private static async Task SavePersistentImpl ( StreamWriter stream , IEnumerable < StoragePair > entries )
42
+ private static async Task SavePersistentImpl ( StreamWriter stream , IEnumerable < ( string key , Value value ) > entries )
33
43
{
34
44
await stream . WriteAsync ( "[NetworkTables Storage 3.0]\n " ) . ConfigureAwait ( false ) ;
35
45
foreach ( var i in entries )
36
46
{
37
- var v = i . Second ;
47
+ var v = i . value ;
38
48
if ( v == null ) continue ;
39
49
switch ( v . Type )
40
50
{
@@ -63,7 +73,7 @@ private static async Task SavePersistentImpl(StreamWriter stream, IEnumerable<St
63
73
continue ;
64
74
}
65
75
66
- await WriteStringAsync ( stream , i . First ) . ConfigureAwait ( false ) ;
76
+ await WriteStringAsync ( stream , i . key ) . ConfigureAwait ( false ) ;
67
77
68
78
await stream . WriteAsync ( '=' ) . ConfigureAwait ( false ) ;
69
79
@@ -260,7 +270,7 @@ private static void UnescapeString(string source, out string dest)
260
270
261
271
public void SavePersistent ( Stream stream , bool periodic )
262
272
{
263
- List < StoragePair > entries = new List < StoragePair > ( ) ;
273
+ List < ( string key , Value value ) > entries = new List < ( string key , Value value ) > ( ) ;
264
274
if ( ! GetPersistentEntries ( periodic , entries ) ) return ;
265
275
StreamWriter w = new StreamWriter ( stream ) ;
266
276
Task task = SavePersistentImpl ( w , entries ) ;
@@ -281,7 +291,7 @@ public string SavePersistent(string filename, bool periodic)
281
291
bak += ".bak" ;
282
292
283
293
//Get entries before creating files
284
- List < StoragePair > entries = new List < StoragePair > ( ) ;
294
+ List < ( string key , Value value ) > entries = new List < ( string key , Value value ) > ( ) ;
285
295
if ( ! GetPersistentEntries ( periodic , entries ) ) return null ;
286
296
287
297
@@ -349,7 +359,7 @@ public async Task<string> SavePersistentAsync(string filename, bool periodic)
349
359
bak += ".bak" ;
350
360
351
361
//Get entries before creating files
352
- List < StoragePair > entries = new List < StoragePair > ( ) ;
362
+ List < ( string key , Value value ) > entries = new List < ( string key , Value value ) > ( ) ;
353
363
if ( ! GetPersistentEntries ( periodic , entries ) ) return null ;
354
364
355
365
string err = null ;
@@ -523,7 +533,7 @@ public async Task<bool> LoadPersistentAsync(Stream stream, Action<int, string> w
523
533
{
524
534
int lineNum = 1 ;
525
535
526
- List < StoragePair > entries = new List < StoragePair > ( ) ;
536
+ List < ( string key , Value value ) > entries = new List < ( string key , Value value ) > ( ) ;
527
537
528
538
List < bool > boolArray = new List < bool > ( ) ;
529
539
List < double > doubleArray = new List < double > ( ) ;
@@ -657,7 +667,7 @@ public async Task<bool> LoadPersistentAsync(Stream stream, Action<int, string> w
657
667
}
658
668
if ( name . Length != 0 && value != null )
659
669
{
660
- entries . Add ( new StoragePair ( name , value ) ) ;
670
+ entries . Add ( ( name , value ) ) ;
661
671
}
662
672
663
673
}
@@ -670,13 +680,13 @@ public async Task<bool> LoadPersistentAsync(Stream stream, Action<int, string> w
670
680
monitor = await m_monitor . EnterAsync ( ) . ConfigureAwait ( false ) ;
671
681
foreach ( var i in entries )
672
682
{
673
- if ( ! m_entries . TryGetValue ( i . First , out Entry entry ) )
683
+ if ( ! m_entries . TryGetValue ( i . key , out Entry entry ) )
674
684
{
675
- entry = new Entry ( i . First ) ;
676
- m_entries . Add ( i . First , entry ) ;
685
+ entry = new Entry ( i . key ) ;
686
+ m_entries . Add ( i . key , entry ) ;
677
687
}
678
688
var oldValue = entry . Value ;
679
- entry . Value = i . Second ;
689
+ entry . Value = i . value ;
680
690
bool wasPersist = entry . IsPersistent ( ) ;
681
691
if ( ! wasPersist ) entry . Flags |= EntryFlags . Persistent ;
682
692
@@ -691,28 +701,28 @@ public async Task<bool> LoadPersistentAsync(Stream stream, Action<int, string> w
691
701
{
692
702
if ( oldValue != null )
693
703
{
694
- m_notifier . NotifyEntry ( i . First , i . Second , ( NotifyFlags . NotifyNew | NotifyFlags . NotifyLocal ) ) ;
704
+ m_notifier . NotifyEntry ( i . key , i . value , ( NotifyFlags . NotifyNew | NotifyFlags . NotifyLocal ) ) ;
695
705
}
696
- else if ( oldValue != i . Second )
706
+ else if ( oldValue != i . value )
697
707
{
698
708
NotifyFlags notifyFlags = NotifyFlags . NotifyUpdate | NotifyFlags . NotifyLocal ;
699
709
if ( ! wasPersist ) notifyFlags |= NotifyFlags . NotifyFlagsChanged ;
700
- m_notifier . NotifyEntry ( i . First , i . Second , notifyFlags ) ;
710
+ m_notifier . NotifyEntry ( i . key , i . value , notifyFlags ) ;
701
711
}
702
712
}
703
713
704
714
if ( m_queueOutgoing == null ) continue ;
705
715
++ entry . SeqNum ;
706
716
707
- if ( oldValue == null || oldValue . Type != i . Second . Type )
717
+ if ( oldValue == null || oldValue . Type != i . value . Type )
708
718
{
709
- msgs . Add ( Message . EntryAssign ( i . First , entry . Id , entry . SeqNum . Value , i . Second , entry . Flags ) ) ;
719
+ msgs . Add ( Message . EntryAssign ( i . key , entry . Id , entry . SeqNum . Value , i . value , entry . Flags ) ) ;
710
720
}
711
721
else if ( entry . Id != 0xffff )
712
722
{
713
- if ( oldValue != i . Second )
723
+ if ( oldValue != i . value )
714
724
{
715
- msgs . Add ( Message . EntryUpdate ( entry . Id , entry . SeqNum . Value , i . Second ) ) ;
725
+ msgs . Add ( Message . EntryUpdate ( entry . Id , entry . SeqNum . Value , i . value ) ) ;
716
726
}
717
727
if ( ! wasPersist )
718
728
msgs . Add ( Message . FlagsUpdate ( entry . Id , entry . Flags ) ) ;
0 commit comments