From 0da1d43c73d4f2aac4375cf658313e305ab18d95 Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Wed, 12 Jan 2022 12:03:05 +0600 Subject: [PATCH 1/5] Add `ReadHandlerState` --- csharp/Platform.Data/ReadHandlerState.cs | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 csharp/Platform.Data/ReadHandlerState.cs diff --git a/csharp/Platform.Data/ReadHandlerState.cs b/csharp/Platform.Data/ReadHandlerState.cs new file mode 100644 index 00000000..62144e23 --- /dev/null +++ b/csharp/Platform.Data/ReadHandlerState.cs @@ -0,0 +1,31 @@ +using System.Collections.Generic; + +namespace Platform.Data +{ + public struct ReadHandlerState + { + private readonly EqualityComparer _equalityComparer = EqualityComparer.Default; + public TLink Result; + public ReadHandler Handler; + public TLink Continue; + public TLink Break; + + public ReadHandlerState(TLink @continue, TLink @break, ReadHandler handler) + { + Continue = @continue; + Break = @break; + Result = @continue; + Handler = handler; + } + + public void Apply(TLink result) + { + if (!_equalityComparer.Equals(Break, result)) + { + return; + } + Handler = null; + Result = Break; + } + } +} From 80f9ae13d145860040f4ab80571842b36d879a30 Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Wed, 12 Jan 2022 12:03:13 +0600 Subject: [PATCH 2/5] Add `WriteHandlerState` --- csharp/Platform.Data/WriteHandlerState.cs | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 csharp/Platform.Data/WriteHandlerState.cs diff --git a/csharp/Platform.Data/WriteHandlerState.cs b/csharp/Platform.Data/WriteHandlerState.cs new file mode 100644 index 00000000..450c4f00 --- /dev/null +++ b/csharp/Platform.Data/WriteHandlerState.cs @@ -0,0 +1,33 @@ +using System.Collections.Generic; + +namespace Platform.Data +{ + public struct WriteHandlerState + { + private readonly EqualityComparer _equalityComparer = EqualityComparer.Default; + public TLink Result; + public WriteHandler Handler; + public TLink Continue; + public TLink Break; + + public WriteHandlerState(TLink @continue, TLink @break, WriteHandler handler) + { + Continue = @continue; + Break = @break; + Result = @continue; + Handler = handler; + } + + public void Apply(TLink result) + { + if (!_equalityComparer.Equals(Break, result)) + { + return; + } + Handler = null; + Result = Break; + } + } +} + + From bd431eb66bd7733da01076c77edc36f5c2fc6602 Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Wed, 12 Jan 2022 12:37:26 +0600 Subject: [PATCH 3/5] Do not `Apply` if `Result==Break` --- csharp/Platform.Data/ReadHandlerState.cs | 4 ++++ csharp/Platform.Data/WriteHandlerState.cs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/csharp/Platform.Data/ReadHandlerState.cs b/csharp/Platform.Data/ReadHandlerState.cs index 62144e23..373d91bf 100644 --- a/csharp/Platform.Data/ReadHandlerState.cs +++ b/csharp/Platform.Data/ReadHandlerState.cs @@ -20,6 +20,10 @@ public ReadHandlerState(TLink @continue, TLink @break, ReadHandler handle public void Apply(TLink result) { + if (_equalityComparer.Equals(Break, Result)) + { + return; + } if (!_equalityComparer.Equals(Break, result)) { return; diff --git a/csharp/Platform.Data/WriteHandlerState.cs b/csharp/Platform.Data/WriteHandlerState.cs index 450c4f00..e9fb2cfe 100644 --- a/csharp/Platform.Data/WriteHandlerState.cs +++ b/csharp/Platform.Data/WriteHandlerState.cs @@ -20,6 +20,10 @@ public WriteHandlerState(TLink @continue, TLink @break, WriteHandler hand public void Apply(TLink result) { + if (_equalityComparer.Equals(Break, Result)) + { + return; + } if (!_equalityComparer.Equals(Break, result)) { return; From 11b75ef6635099720f5512911ec350011869e63c Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Thu, 13 Jan 2022 14:25:21 +0600 Subject: [PATCH 4/5] Import `Platform.Delegates` --- csharp/Platform.Data/ReadHandlerState.cs | 1 + csharp/Platform.Data/WriteHandlerState.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/csharp/Platform.Data/ReadHandlerState.cs b/csharp/Platform.Data/ReadHandlerState.cs index 373d91bf..0bf0c9f4 100644 --- a/csharp/Platform.Data/ReadHandlerState.cs +++ b/csharp/Platform.Data/ReadHandlerState.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Platform.Delegates; namespace Platform.Data { diff --git a/csharp/Platform.Data/WriteHandlerState.cs b/csharp/Platform.Data/WriteHandlerState.cs index e9fb2cfe..a8cd626f 100644 --- a/csharp/Platform.Data/WriteHandlerState.cs +++ b/csharp/Platform.Data/WriteHandlerState.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Platform.Delegates; namespace Platform.Data { From 6d6b351e4abca1d7315e3345b8e3311f56270135 Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Thu, 13 Jan 2022 14:39:34 +0600 Subject: [PATCH 5/5] Initialize `_equalityComparer` in constructor --- csharp/Platform.Data/ReadHandlerState.cs | 3 ++- csharp/Platform.Data/WriteHandlerState.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/csharp/Platform.Data/ReadHandlerState.cs b/csharp/Platform.Data/ReadHandlerState.cs index 0bf0c9f4..7d59a076 100644 --- a/csharp/Platform.Data/ReadHandlerState.cs +++ b/csharp/Platform.Data/ReadHandlerState.cs @@ -5,7 +5,7 @@ namespace Platform.Data { public struct ReadHandlerState { - private readonly EqualityComparer _equalityComparer = EqualityComparer.Default; + private readonly EqualityComparer _equalityComparer; public TLink Result; public ReadHandler Handler; public TLink Continue; @@ -13,6 +13,7 @@ public struct ReadHandlerState public ReadHandlerState(TLink @continue, TLink @break, ReadHandler handler) { + _equalityComparer = EqualityComparer.Default; Continue = @continue; Break = @break; Result = @continue; diff --git a/csharp/Platform.Data/WriteHandlerState.cs b/csharp/Platform.Data/WriteHandlerState.cs index a8cd626f..6ae8c1b2 100644 --- a/csharp/Platform.Data/WriteHandlerState.cs +++ b/csharp/Platform.Data/WriteHandlerState.cs @@ -5,7 +5,7 @@ namespace Platform.Data { public struct WriteHandlerState { - private readonly EqualityComparer _equalityComparer = EqualityComparer.Default; + private readonly EqualityComparer _equalityComparer; public TLink Result; public WriteHandler Handler; public TLink Continue; @@ -13,6 +13,7 @@ public struct WriteHandlerState public WriteHandlerState(TLink @continue, TLink @break, WriteHandler handler) { + _equalityComparer = EqualityComparer.Default; Continue = @continue; Break = @break; Result = @continue;