Skip to content

Performance: Use Span<T> when parsing #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jaredcnance opened this issue Apr 11, 2018 · 0 comments
Closed

Performance: Use Span<T> when parsing #258

jaredcnance opened this issue Apr 11, 2018 · 0 comments

Comments

@jaredcnance
Copy link
Contributor

jaredcnance commented Apr 11, 2018

Split is going to allocate at least 2 additional string, and in these cases we should be able to just use Span<T> and allocate only when required.

private static bool ContainsMediaTypeParameters(string mediaType)
{
var mediaTypeArr = mediaType.Split(';');
return (mediaTypeArr[0] == Constants.ContentType && mediaTypeArr.Length == 2);
}

var propertyName = key.Split(OPEN_BRACKET, CLOSE_BRACKET)[1];
var values = value.Split(COMMA);
foreach (var val in values)
{
(var operation, var filterValue) = ParseFilterOperation(val);
queries.Add(new FilterQuery(propertyName, filterValue, operation));
}

private string GetNamespaceFromPath(string path, string entityName)
{
var nSpace = string.Empty;
var segments = path.Split('/');
for (var i = 1; i < segments.Length; i++)
{
if (segments[i].ToLower() == entityName)
break;
nSpace += $"/{segments[i]}";
}
return nSpace;
}

var relationshipArray = filterQuery.Attribute.Split('.');
var relationship = GetRelationship(relationshipArray[0]);

var path = context.Request.Path.Value.Split('/');

crfloyd pushed a commit to crfloyd/JsonApiDotNetCore that referenced this issue Apr 24, 2018
… string as Span<char> given a char delimeter. Language version updated to 7.2 due to need for ref Struct to utilize Span<T> as a field.
crfloyd pushed a commit to crfloyd/JsonApiDotNetCore that referenced this issue Apr 24, 2018
…estMiddleware, JsonApiContext, and QueryParser to utilize new SpanSplitter library to avoid unnecessary intermediate string creation.
@crfloyd crfloyd mentioned this issue Apr 24, 2018
3 tasks
crfloyd pushed a commit to crfloyd/JsonApiDotNetCore that referenced this issue Apr 24, 2018
crfloyd added a commit to crfloyd/JsonApiDotNetCore that referenced this issue Apr 25, 2018
crfloyd added a commit to crfloyd/JsonApiDotNetCore that referenced this issue Apr 25, 2018
…pdates usages and unit tests to use extension method.
jaredcnance added a commit that referenced this issue May 6, 2018
jaredcnance pushed a commit that referenced this issue Aug 12, 2018
…<char> given a char delimeter. Language version updated to 7.2 due to need for ref Struct to utilize Span<T> as a field.
jaredcnance pushed a commit that referenced this issue Aug 12, 2018
…JsonApiContext, and QueryParser to utilize new SpanSplitter library to avoid unnecessary intermediate string creation.
jaredcnance pushed a commit that referenced this issue Aug 12, 2018
jaredcnance pushed a commit that referenced this issue Aug 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant