-
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.
Reduce heap allocation by deferring formatting of log and error messa…
…ges until actually accessed by consumer
- Loading branch information
Showing
14 changed files
with
102 additions
and
36 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
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 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 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Globalization; | ||
|
||
namespace ConfigCat.Client.Utils; | ||
|
||
internal struct LazyString | ||
{ | ||
private readonly string? format; | ||
private object? argsOrValue; | ||
|
||
public LazyString(string? value) | ||
{ | ||
this.format = null; | ||
this.argsOrValue = value; | ||
} | ||
|
||
public LazyString(string format, params object?[]? args) | ||
{ | ||
this.format = format; | ||
this.argsOrValue = args ?? ArrayUtils.EmptyArray<string>(); | ||
} | ||
|
||
public string? Value => this.argsOrValue as string; | ||
|
||
public override string? ToString() | ||
{ | ||
var argsOrValue = this.argsOrValue; | ||
if (argsOrValue is null) | ||
{ | ||
return null; | ||
} | ||
|
||
if (argsOrValue is not string value) | ||
{ | ||
var args = (object?[])argsOrValue; | ||
this.argsOrValue = value = string.Format(CultureInfo.InvariantCulture, this.format!, args); | ||
} | ||
|
||
return value; | ||
} | ||
|
||
public static implicit operator LazyString(string? value) => new LazyString(value); | ||
} |