garnet
garnet copied to clipboard
Reduce allocations around the use of ArgSlice
This PR includes various little refactoring and changes that can be considered "peanut-butter" as Toub terms them.
I have shared my concerns about this type in general on Garnet discord already so I'm not gonna repeat them here 😄
Commits
- Make
ArgSlice.Bytesa method and rename it to ToArray- This makes it clearer to the API consumers that this action is not free. This
To-prefix pattern may seem familiar from the BCL.
- This makes it clearer to the API consumers that this action is not free. This
- Mark all properties on ArgSlice as readonly
- Remove unnecessary allocations for ArgSlice length checks
- It indeed was not clear whether accessing
Bytesis cheap. UseLengthproperty directly instead and avoid the unnecessary allocation.
- It indeed was not clear whether accessing
- Remove misc. allocations relating to use of ArgSlice
- Switch some ArgSlice initializations to use constructor instead of initializer expression
- Use the public
ArgSlice.Lengthproperty instead of the internal field where applicable