-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed the language version to the latest
- Loading branch information
1 parent
90a9a1d
commit 326c8e3
Showing
15 changed files
with
446 additions
and
458 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,30 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Running; | ||
|
||
namespace Yoh.Text.Json.NamingPolicies.Benchmarks | ||
namespace Yoh.Text.Json.NamingPolicies.Benchmarks; | ||
|
||
[MemoryDiagnoser] | ||
public class Benchmarks | ||
{ | ||
[MemoryDiagnoser] | ||
public class Benchmarks | ||
{ | ||
public static void Main(string[] args) => | ||
BenchmarkRunner.Run<Benchmarks>(); | ||
public static void Main(string[] args) => | ||
BenchmarkRunner.Run<Benchmarks>(); | ||
|
||
[Params("XMLHttpRequest", "ATowelItSaysIsAboutTheMostMassivelyUsefulThingAnInterstellarHitchhikerCanHave_PartlyItHasGreatPracticalValue_YouCanWrapItAroundYouForWarmthAsYouBoundAcrossTheColdMoonsOfJaglanBeta_YouCanLieOnItOnTheBrilliantMarbleSandedBeachesOfSantraginusVInhalingTheHeadySeaVapors_YouCanSleepUnderItBeneathTheStarsWhichShineSoRedlyOnTheDesertWorldOfKakrafoon_UseItToSailAMiniraftDownTheSlowHeavyRiverMoth_WetItForUseInHandToHandCombat_WrapItRoundYourHeadToWardOffNoxiousFumesOrAvoidTheGazeOfTheRavenousBugblatterBeastOfTraalAMindBogglinglyStupidAnimal_ItAssumesThatIfYouCantSeeItItCantSeeYouDaftAsABrushButVeryVeryRavenous_YouCanWaveYourTowelInEmergenciesAsADistressSignalAndOfCourseDryYourselfOfWithItIfItStillSeemsToBeCleanEnough")] | ||
public string Name { get; set; } = string.Empty; | ||
[Params("XMLHttpRequest", "ATowelItSaysIsAboutTheMostMassivelyUsefulThingAnInterstellarHitchhikerCanHave_PartlyItHasGreatPracticalValue_YouCanWrapItAroundYouForWarmthAsYouBoundAcrossTheColdMoonsOfJaglanBeta_YouCanLieOnItOnTheBrilliantMarbleSandedBeachesOfSantraginusVInhalingTheHeadySeaVapors_YouCanSleepUnderItBeneathTheStarsWhichShineSoRedlyOnTheDesertWorldOfKakrafoon_UseItToSailAMiniraftDownTheSlowHeavyRiverMoth_WetItForUseInHandToHandCombat_WrapItRoundYourHeadToWardOffNoxiousFumesOrAvoidTheGazeOfTheRavenousBugblatterBeastOfTraalAMindBogglinglyStupidAnimal_ItAssumesThatIfYouCantSeeItItCantSeeYouDaftAsABrushButVeryVeryRavenous_YouCanWaveYourTowelInEmergenciesAsADistressSignalAndOfCourseDryYourselfOfWithItIfItStillSeemsToBeCleanEnough")] | ||
public string Name { get; set; } = string.Empty; | ||
|
||
[Benchmark] | ||
public string SnakeLowerCase() => | ||
JsonNamingPolicies.SnakeCaseLower.ConvertName(Name); | ||
[Benchmark] | ||
public string SnakeLowerCase() => | ||
JsonNamingPolicies.SnakeCaseLower.ConvertName(Name); | ||
|
||
[Benchmark] | ||
public string SnakeUpperCase() => | ||
JsonNamingPolicies.SnakeCaseUpper.ConvertName(Name); | ||
[Benchmark] | ||
public string SnakeUpperCase() => | ||
JsonNamingPolicies.SnakeCaseUpper.ConvertName(Name); | ||
|
||
[Benchmark] | ||
public string KebabLowerCase() => | ||
JsonNamingPolicies.KebabCaseLower.ConvertName(Name); | ||
[Benchmark] | ||
public string KebabLowerCase() => | ||
JsonNamingPolicies.KebabCaseLower.ConvertName(Name); | ||
|
||
[Benchmark] | ||
public string KebabUpperCase() => | ||
JsonNamingPolicies.KebabCaseUpper.ConvertName(Name); | ||
} | ||
[Benchmark] | ||
public string KebabUpperCase() => | ||
JsonNamingPolicies.KebabCaseUpper.ConvertName(Name); | ||
} |
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,18 +1,17 @@ | ||
using System; | ||
|
||
namespace Yoh.Text.Json.NamingPolicies | ||
namespace Yoh.Text.Json.NamingPolicies; | ||
|
||
internal sealed class JsonCamelCaseNamingPolicy : JsonNamingPolicyBase | ||
{ | ||
internal sealed class JsonCamelCaseNamingPolicy : JsonNamingPolicyBase | ||
protected override int TryWriteWord(bool first, ReadOnlySpan<char> word, Span<char> destination) | ||
{ | ||
protected override int TryWriteWord(bool first, ReadOnlySpan<char> word, Span<char> destination) | ||
var written = word.ToLowerInvariant(destination); | ||
if (written > 0 && !first) | ||
{ | ||
var written = word.ToLowerInvariant(destination); | ||
if (written > 0 && !first) | ||
{ | ||
destination[0] = char.ToUpperInvariant(destination[0]); | ||
} | ||
|
||
return written; | ||
destination[0] = char.ToUpperInvariant(destination[0]); | ||
} | ||
|
||
return written; | ||
} | ||
} |
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,8 +1,7 @@ | ||
namespace Yoh.Text.Json.NamingPolicies | ||
namespace Yoh.Text.Json.NamingPolicies; | ||
|
||
internal static class JsonConstants | ||
{ | ||
internal static class JsonConstants | ||
{ | ||
public const int StackallocByteThreshold = 256; | ||
public const int StackallocCharThreshold = StackallocByteThreshold / 2; | ||
} | ||
public const int StackallocByteThreshold = 256; | ||
public const int StackallocCharThreshold = StackallocByteThreshold / 2; | ||
} |
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,10 +1,9 @@ | ||
namespace Yoh.Text.Json.NamingPolicies | ||
namespace Yoh.Text.Json.NamingPolicies; | ||
|
||
internal sealed class JsonKebabCaseLowerNamingPolicy : JsonSeparatorNamingPolicy | ||
{ | ||
internal sealed class JsonKebabCaseLowerNamingPolicy : JsonSeparatorNamingPolicy | ||
public JsonKebabCaseLowerNamingPolicy() | ||
: base(lowercase: true, separator: '-') | ||
{ | ||
public JsonKebabCaseLowerNamingPolicy() | ||
: base(lowercase: true, separator: '-') | ||
{ | ||
} | ||
} | ||
} |
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,10 +1,9 @@ | ||
namespace Yoh.Text.Json.NamingPolicies | ||
namespace Yoh.Text.Json.NamingPolicies; | ||
|
||
internal sealed class JsonKebabCaseUpperNamingPolicy : JsonSeparatorNamingPolicy | ||
{ | ||
internal sealed class JsonKebabCaseUpperNamingPolicy : JsonSeparatorNamingPolicy | ||
public JsonKebabCaseUpperNamingPolicy() | ||
: base(lowercase: false, separator: '-') | ||
{ | ||
public JsonKebabCaseUpperNamingPolicy() | ||
: base(lowercase: false, separator: '-') | ||
{ | ||
} | ||
} | ||
} |
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,26 +1,25 @@ | ||
using System.Text.Json; | ||
|
||
namespace Yoh.Text.Json.NamingPolicies | ||
namespace Yoh.Text.Json.NamingPolicies; | ||
|
||
public static class JsonNamingPolicies | ||
{ | ||
public static class JsonNamingPolicies | ||
{ | ||
private static JsonCamelCaseNamingPolicy? _camelCase; | ||
private static JsonPascalCaseNamingPolicy? _pascalCase; | ||
private static JsonSnakeCaseLowerNamingPolicy? _snakeCaseLower; | ||
private static JsonSnakeCaseUpperNamingPolicy? _snakeCaseUpper; | ||
private static JsonKebabCaseLowerNamingPolicy? _kebabCaseLower; | ||
private static JsonKebabCaseUpperNamingPolicy? _kebabCaseUpper; | ||
private static JsonCamelCaseNamingPolicy? _camelCase; | ||
private static JsonPascalCaseNamingPolicy? _pascalCase; | ||
private static JsonSnakeCaseLowerNamingPolicy? _snakeCaseLower; | ||
private static JsonSnakeCaseUpperNamingPolicy? _snakeCaseUpper; | ||
private static JsonKebabCaseLowerNamingPolicy? _kebabCaseLower; | ||
private static JsonKebabCaseUpperNamingPolicy? _kebabCaseUpper; | ||
|
||
public static JsonNamingPolicy CamelCase => _camelCase ??= new JsonCamelCaseNamingPolicy(); | ||
public static JsonNamingPolicy CamelCase => _camelCase ??= new JsonCamelCaseNamingPolicy(); | ||
|
||
public static JsonNamingPolicy PascalCase => _pascalCase ??= new JsonPascalCaseNamingPolicy(); | ||
public static JsonNamingPolicy PascalCase => _pascalCase ??= new JsonPascalCaseNamingPolicy(); | ||
|
||
public static JsonNamingPolicy SnakeCaseLower => _snakeCaseLower ??= new JsonSnakeCaseLowerNamingPolicy(); | ||
public static JsonNamingPolicy SnakeCaseLower => _snakeCaseLower ??= new JsonSnakeCaseLowerNamingPolicy(); | ||
|
||
public static JsonNamingPolicy SnakeCaseUpper => _snakeCaseUpper ??= new JsonSnakeCaseUpperNamingPolicy(); | ||
public static JsonNamingPolicy SnakeCaseUpper => _snakeCaseUpper ??= new JsonSnakeCaseUpperNamingPolicy(); | ||
|
||
public static JsonNamingPolicy KebabCaseLower => _kebabCaseLower ??= new JsonKebabCaseLowerNamingPolicy(); | ||
public static JsonNamingPolicy KebabCaseLower => _kebabCaseLower ??= new JsonKebabCaseLowerNamingPolicy(); | ||
|
||
public static JsonNamingPolicy KebabCaseUpper => _kebabCaseUpper ??= new JsonKebabCaseUpperNamingPolicy(); | ||
} | ||
public static JsonNamingPolicy KebabCaseUpper => _kebabCaseUpper ??= new JsonKebabCaseUpperNamingPolicy(); | ||
} |
Oops, something went wrong.