Skip to content

Commit 15f4660

Browse files
committed
Revert "Removes StoragePair and replaces with tuple"
This reverts commit 8c092af.
1 parent 8c092af commit 15f4660

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

src/FRC.NetworkTables/Storage.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@ namespace NetworkTables
1313
{
1414
internal partial class Storage : IDisposable
1515
{
16+
internal struct StoragePair : IComparable<StoragePair>
17+
{
18+
public string First { get; }
19+
public Value Second { get; }
20+
21+
public StoragePair(string first, Value second)
22+
{
23+
First = first;
24+
Second = second;
25+
}
26+
27+
public int CompareTo(StoragePair other)
28+
{
29+
return string.Compare(First, other.First, StringComparison.Ordinal);
30+
}
31+
}
32+
1633
private static Storage s_instance;
1734

1835
public static Storage Instance

src/FRC.NetworkTables/StorageSaving.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace NetworkTables
1212
{
1313
internal partial class Storage
1414
{
15-
private bool GetPersistentEntries(bool periodic, List<(string key, Value value)> entries)
15+
private bool GetPersistentEntries(bool periodic, List<StoragePair> entries)
1616
{
1717
using (m_monitor.Enter())
1818
{
@@ -22,19 +22,19 @@ private bool GetPersistentEntries(bool periodic, List<(string key, Value value)>
2222
{
2323
Entry entry = i.Value;
2424
if (!entry.IsPersistent()) continue;
25-
entries.Add((i.Key, entry.Value));
25+
entries.Add(new StoragePair(i.Key, entry.Value));
2626
}
2727
}
2828
entries.Sort();
2929
return true;
3030
}
3131

32-
private static async Task SavePersistentImpl(StreamWriter stream, IEnumerable<(string key, Value value)> entries)
32+
private static async Task SavePersistentImpl(StreamWriter stream, IEnumerable<StoragePair> entries)
3333
{
3434
await stream.WriteAsync("[NetworkTables Storage 3.0]\n").ConfigureAwait(false);
3535
foreach (var i in entries)
3636
{
37-
var v = i.value;
37+
var v = i.Second;
3838
if (v == null) continue;
3939
switch (v.Type)
4040
{
@@ -63,7 +63,7 @@ private static async Task SavePersistentImpl(StreamWriter stream, IEnumerable<(s
6363
continue;
6464
}
6565

66-
await WriteStringAsync(stream, i.key).ConfigureAwait(false);
66+
await WriteStringAsync(stream, i.First).ConfigureAwait(false);
6767

6868
await stream.WriteAsync('=').ConfigureAwait(false);
6969

@@ -260,7 +260,7 @@ private static void UnescapeString(string source, out string dest)
260260

261261
public void SavePersistent(Stream stream, bool periodic)
262262
{
263-
List<(string key, Value value)> entries = new List<(string key, Value value)>();
263+
List<StoragePair> entries = new List<StoragePair>();
264264
if (!GetPersistentEntries(periodic, entries)) return;
265265
StreamWriter w = new StreamWriter(stream);
266266
Task task = SavePersistentImpl(w, entries);
@@ -281,7 +281,7 @@ public string SavePersistent(string filename, bool periodic)
281281
bak += ".bak";
282282

283283
//Get entries before creating files
284-
List<(string key, Value value)> entries = new List<(string key, Value value)>();
284+
List<StoragePair> entries = new List<StoragePair>();
285285
if (!GetPersistentEntries(periodic, entries)) return null;
286286

287287

@@ -349,7 +349,7 @@ public async Task<string> SavePersistentAsync(string filename, bool periodic)
349349
bak += ".bak";
350350

351351
//Get entries before creating files
352-
List<(string key, Value value)> entries = new List<(string key, Value value)>();
352+
List<StoragePair> entries = new List<StoragePair>();
353353
if (!GetPersistentEntries(periodic, entries)) return null;
354354

355355
string err = null;
@@ -523,7 +523,7 @@ public async Task<bool> LoadPersistentAsync(Stream stream, Action<int, string> w
523523
{
524524
int lineNum = 1;
525525

526-
List<(string key, Value value)> entries = new List<(string key, Value value)>();
526+
List<StoragePair> entries = new List<StoragePair>();
527527

528528
List<bool> boolArray = new List<bool>();
529529
List<double> doubleArray = new List<double>();
@@ -657,7 +657,7 @@ public async Task<bool> LoadPersistentAsync(Stream stream, Action<int, string> w
657657
}
658658
if (name.Length != 0 && value != null)
659659
{
660-
entries.Add((name, value));
660+
entries.Add(new StoragePair(name, value));
661661
}
662662

663663
}
@@ -670,13 +670,13 @@ public async Task<bool> LoadPersistentAsync(Stream stream, Action<int, string> w
670670
monitor = await m_monitor.EnterAsync().ConfigureAwait(false);
671671
foreach (var i in entries)
672672
{
673-
if (!m_entries.TryGetValue(i.key, out Entry entry))
673+
if (!m_entries.TryGetValue(i.First, out Entry entry))
674674
{
675-
entry = new Entry(i.key);
676-
m_entries.Add(i.key, entry);
675+
entry = new Entry(i.First);
676+
m_entries.Add(i.First, entry);
677677
}
678678
var oldValue = entry.Value;
679-
entry.Value = i.value;
679+
entry.Value = i.Second;
680680
bool wasPersist = entry.IsPersistent();
681681
if (!wasPersist) entry.Flags |= EntryFlags.Persistent;
682682

@@ -691,28 +691,28 @@ public async Task<bool> LoadPersistentAsync(Stream stream, Action<int, string> w
691691
{
692692
if (oldValue != null)
693693
{
694-
m_notifier.NotifyEntry(i.key, i.value, (NotifyFlags.NotifyNew | NotifyFlags.NotifyLocal));
694+
m_notifier.NotifyEntry(i.First, i.Second, (NotifyFlags.NotifyNew | NotifyFlags.NotifyLocal));
695695
}
696-
else if (oldValue != i.value)
696+
else if (oldValue != i.Second)
697697
{
698698
NotifyFlags notifyFlags = NotifyFlags.NotifyUpdate | NotifyFlags.NotifyLocal;
699699
if (!wasPersist) notifyFlags |= NotifyFlags.NotifyFlagsChanged;
700-
m_notifier.NotifyEntry(i.key, i.value, notifyFlags);
700+
m_notifier.NotifyEntry(i.First, i.Second, notifyFlags);
701701
}
702702
}
703703

704704
if (m_queueOutgoing == null) continue;
705705
++entry.SeqNum;
706706

707-
if (oldValue == null || oldValue.Type != i.value.Type)
707+
if (oldValue == null || oldValue.Type != i.Second.Type)
708708
{
709-
msgs.Add(Message.EntryAssign(i.key, entry.Id, entry.SeqNum.Value, i.value, entry.Flags));
709+
msgs.Add(Message.EntryAssign(i.First, entry.Id, entry.SeqNum.Value, i.Second, entry.Flags));
710710
}
711711
else if (entry.Id != 0xffff)
712712
{
713-
if (oldValue != i.value)
713+
if (oldValue != i.Second)
714714
{
715-
msgs.Add(Message.EntryUpdate(entry.Id, entry.SeqNum.Value, i.value));
715+
msgs.Add(Message.EntryUpdate(entry.Id, entry.SeqNum.Value, i.Second));
716716
}
717717
if (!wasPersist)
718718
msgs.Add(Message.FlagsUpdate(entry.Id, entry.Flags));

0 commit comments

Comments
 (0)