-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improves error reporting when setting type and default value type mismatch * Improves ConfigDeserializer performance by using ETag for change detection instead of calculating a hash * Improves SHA1 hashing implementation * Eliminates ModuleInitalizer trick used in tests because MSTest provides that feature out of the box
- Loading branch information
Showing
18 changed files
with
334 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
...nfigCat.Client.Tests/ModuleInitializer.cs → ...igCat.Client.Tests/AssemblyInitializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
using ConfigCat.Client.Evaluation; | ||
using System; | ||
using System.Data.HashFunction; | ||
using System.Data.HashFunction.MurmurHash; | ||
|
||
namespace ConfigCat.Client | ||
{ | ||
internal class ConfigDeserializer : IConfigDeserializer | ||
{ | ||
private readonly IHashFunction hasher = MurmurHash3Factory.Instance.Create(new MurmurHash3Config { HashSizeInBits = 128 }); | ||
private SettingsWithPreferences lastSerializedSettings; | ||
private byte[] hashToCompare; | ||
private SettingsWithPreferences lastDeserializedSettings; | ||
private string lastConfig; | ||
private string lastHttpETag; | ||
|
||
public bool TryDeserialize(string config, out SettingsWithPreferences settings) | ||
public bool TryDeserialize(string config, string httpETag, out SettingsWithPreferences settings) | ||
{ | ||
if (config == null) | ||
{ | ||
settings = null; | ||
return false; | ||
} | ||
|
||
var hash = this.hasher.ComputeHash(config).Hash; | ||
if (CompareByteArrays(this.hashToCompare, hash)) | ||
var configContentHasChanged = this.lastHttpETag is not null && httpETag is not null | ||
? this.lastHttpETag != httpETag | ||
: this.lastConfig != config; | ||
|
||
if (!configContentHasChanged) | ||
{ | ||
settings = this.lastSerializedSettings; | ||
settings = this.lastDeserializedSettings; | ||
return true; | ||
} | ||
|
||
this.lastSerializedSettings = settings = config.Deserialize<SettingsWithPreferences>(); | ||
this.hashToCompare = hash; | ||
this.lastDeserializedSettings = settings = config.Deserialize<SettingsWithPreferences>(); | ||
this.lastConfig = config; | ||
this.lastHttpETag = httpETag; | ||
return true; | ||
} | ||
|
||
private static bool CompareByteArrays(ReadOnlySpan<byte> b1, ReadOnlySpan<byte> b2) => b1.SequenceEqual(b2); | ||
} | ||
} |
Oops, something went wrong.