-
Notifications
You must be signed in to change notification settings - Fork 543
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Eliminating usage of Enum.Parse/Enum.TryParse from critical performan…
…ce paths (#806) * Eliminating usage of Enum.Parse/TryParse from critical performance paths * wip * wip * bugfix * format * Fixing comment * Moving parsing logic to SessionParseState extension methods * Removing unnecessary usings * format * Added 2 parsers
- Loading branch information
Showing
20 changed files
with
382 additions
and
214 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
using Garnet.common; | ||
using Garnet.server; | ||
|
||
namespace Garnet.cluster | ||
{ | ||
/// <summary> | ||
/// Extension methods for <see cref="SessionParseState"/>. | ||
/// </summary> | ||
public static class SessionParseStateExtensions | ||
{ | ||
/// <summary> | ||
/// Parse slot state from parse state at specified index | ||
/// </summary> | ||
/// <param name="parseState">The parse state</param> | ||
/// <param name="idx">The argument index</param> | ||
/// <param name="value">Parsed value</param> | ||
/// <returns>True if value parsed successfully</returns> | ||
public static bool TryGetSlotState(this SessionParseState parseState, int idx, out SlotState value) | ||
{ | ||
value = default; | ||
var sbArg = parseState.GetArgSliceByRef(idx).ReadOnlySpan; | ||
|
||
if (sbArg.EqualsUpperCaseSpanIgnoringCase("OFFLINE"u8)) | ||
value = SlotState.OFFLINE; | ||
else if (sbArg.EqualsUpperCaseSpanIgnoringCase("STABLE"u8)) | ||
value = SlotState.STABLE; | ||
else if (sbArg.EqualsUpperCaseSpanIgnoringCase("MIGRATING"u8)) | ||
value = SlotState.MIGRATING; | ||
else if (sbArg.EqualsUpperCaseSpanIgnoringCase("IMPORTING"u8)) | ||
value = SlotState.IMPORTING; | ||
else if (sbArg.EqualsUpperCaseSpanIgnoringCase("FAIL"u8)) | ||
value = SlotState.FAIL; | ||
else if (sbArg.EqualsUpperCaseSpanIgnoringCase("NODE"u8)) | ||
value = SlotState.NODE; | ||
else if (sbArg.EqualsUpperCaseSpanIgnoringCase("INVALID"u8)) | ||
value = SlotState.INVALID; | ||
else return false; | ||
|
||
return true; | ||
} | ||
|
||
/// <summary> | ||
/// Parse failover option from parse state at specified index | ||
/// </summary> | ||
/// <param name="parseState">The parse state</param> | ||
/// <param name="idx">The argument index</param> | ||
/// <param name="value">Parsed value</param> | ||
/// <returns>True if value parsed successfully</returns> | ||
public static bool TryGetFailoverOption(this SessionParseState parseState, int idx, out FailoverOption value) | ||
{ | ||
value = default; | ||
var sbArg = parseState.GetArgSliceByRef(idx).ReadOnlySpan; | ||
|
||
if (sbArg.EqualsUpperCaseSpanIgnoringCase("DEFAULT"u8)) | ||
value = FailoverOption.DEFAULT; | ||
else if (sbArg.EqualsUpperCaseSpanIgnoringCase("INVALID"u8)) | ||
value = FailoverOption.INVALID; | ||
else if (sbArg.EqualsUpperCaseSpanIgnoringCase("TO"u8)) | ||
value = FailoverOption.TO; | ||
else if (sbArg.EqualsUpperCaseSpanIgnoringCase("FORCE"u8)) | ||
value = FailoverOption.FORCE; | ||
else if (sbArg.EqualsUpperCaseSpanIgnoringCase("ABORT"u8)) | ||
value = FailoverOption.ABORT; | ||
else if (sbArg.EqualsUpperCaseSpanIgnoringCase("TIMEOUT"u8)) | ||
value = FailoverOption.TIMEOUT; | ||
else if (sbArg.EqualsUpperCaseSpanIgnoringCase("TAKEOVER"u8)) | ||
value = FailoverOption.TAKEOVER; | ||
else return false; | ||
|
||
return true; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.