Skip to content

Commit 2bbf36c

Browse files
committed
Optimize StringBuilder calls to avoid calling ToString() twice, remove redundant PublicName in interpolations
1 parent 238c933 commit 2bbf36c

File tree

17 files changed

+33
-33
lines changed

17 files changed

+33
-33
lines changed

src/Examples/DapperExample/TranslationToSql/Builders/SelectStatementBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ public override SqlTreeNode VisitResourceFieldChain(ResourceFieldChainExpression
552552
throw new JsonApiException(new ErrorObject(HttpStatusCode.BadRequest)
553553
{
554554
Title = "Sorting or filtering on the requested attribute is unavailable.",
555-
Detail = $"Sorting or filtering on attribute '{attribute.PublicName}' is unavailable because it is unmapped."
555+
Detail = $"Sorting or filtering on attribute '{attribute}' is unavailable because it is unmapped."
556556
});
557557
}
558558

src/JsonApiDotNetCore/Configuration/ResourceGraphBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private static void ValidateAttributesInDerivedType(ResourceType resourceType)
130130
if (resourceType.FindAttributeByPublicName(attribute.PublicName) == null)
131131
{
132132
throw new InvalidConfigurationException(
133-
$"Attribute '{attribute.PublicName}' from base type '{resourceType.BaseType.ClrType}' does not exist in derived type '{resourceType.ClrType}'.");
133+
$"Attribute '{attribute}' from base type '{resourceType.BaseType.ClrType}' does not exist in derived type '{resourceType.ClrType}'.");
134134
}
135135
}
136136
}
@@ -142,7 +142,7 @@ private static void ValidateRelationshipsInDerivedType(ResourceType resourceType
142142
if (resourceType.FindRelationshipByPublicName(relationship.PublicName) == null)
143143
{
144144
throw new InvalidConfigurationException(
145-
$"Relationship '{relationship.PublicName}' from base type '{resourceType.BaseType.ClrType}' does not exist in derived type '{resourceType.ClrType}'.");
145+
$"Relationship '{relationship}' from base type '{resourceType.BaseType.ClrType}' does not exist in derived type '{resourceType.ClrType}'.");
146146
}
147147
}
148148
}

src/JsonApiDotNetCore/Queries/Expressions/AnyExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private string InnerToString(bool toFullString)
5656

5757
builder.Append(Keywords.Any);
5858
builder.Append('(');
59-
builder.Append(toFullString ? TargetAttribute.ToFullString() : TargetAttribute);
59+
builder.Append(toFullString ? TargetAttribute.ToFullString() : TargetAttribute.ToString());
6060
builder.Append(',');
6161
builder.Append(string.Join(',', Constants.Select(constant => toFullString ? constant.ToFullString() : constant.ToString()).OrderBy(value => value)));
6262
builder.Append(')');

src/JsonApiDotNetCore/Queries/Expressions/HasExpression.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ private string InnerToString(bool toFullString)
5858
var builder = new StringBuilder();
5959
builder.Append(Keywords.Has);
6060
builder.Append('(');
61-
builder.Append(toFullString ? TargetCollection.ToFullString() : TargetCollection);
61+
builder.Append(toFullString ? TargetCollection.ToFullString() : TargetCollection.ToString());
6262

6363
if (Filter != null)
6464
{
6565
builder.Append(',');
66-
builder.Append(toFullString ? Filter.ToFullString() : Filter);
66+
builder.Append(toFullString ? Filter.ToFullString() : Filter.ToString());
6767
}
6868

6969
builder.Append(')');

src/JsonApiDotNetCore/Queries/Expressions/IncludeElementExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public override string ToFullString()
5757
private string InnerToString(bool toFullString)
5858
{
5959
var builder = new StringBuilder();
60-
builder.Append(toFullString ? $"{Relationship.LeftType.PublicName}:{Relationship.PublicName}" : Relationship.PublicName);
60+
builder.Append(toFullString ? $"{Relationship.LeftType}:{Relationship}" : Relationship.ToString());
6161

6262
if (Children.Count > 0)
6363
{

src/JsonApiDotNetCore/Queries/Expressions/IsTypeExpression.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private string InnerToString(bool toFullString)
7171

7272
if (TargetToOneRelationship != null)
7373
{
74-
builder.Append(toFullString ? TargetToOneRelationship.ToFullString() : TargetToOneRelationship);
74+
builder.Append(toFullString ? TargetToOneRelationship.ToFullString() : TargetToOneRelationship.ToString());
7575
}
7676

7777
builder.Append(',');
@@ -80,7 +80,7 @@ private string InnerToString(bool toFullString)
8080
if (Child != null)
8181
{
8282
builder.Append(',');
83-
builder.Append(toFullString ? Child.ToFullString() : Child);
83+
builder.Append(toFullString ? Child.ToFullString() : Child.ToString());
8484
}
8585

8686
builder.Append(')');

src/JsonApiDotNetCore/Queries/Expressions/MatchTextExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private string InnerToString(bool toFullString)
7272

7373
builder.Append(toFullString
7474
? string.Join(',', TargetAttribute.ToFullString(), TextValue.ToFullString())
75-
: string.Join(',', TargetAttribute, TextValue));
75+
: string.Join(',', TargetAttribute.ToString(), TextValue.ToString()));
7676

7777
builder.Append(')');
7878

src/JsonApiDotNetCore/Queries/Expressions/ResourceFieldChainExpression.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ public override TResult Accept<TArgument, TResult>(QueryExpressionVisitor<TArgum
4545

4646
public override string ToString()
4747
{
48-
return string.Join('.', Fields.Select(field => field.PublicName));
48+
return string.Join('.', Fields.Select(field => field.ToString()));
4949
}
5050

5151
public override string ToFullString()
5252
{
53-
return string.Join('.', Fields.Select(field => $"{field.Type.PublicName}:{field.PublicName}"));
53+
return string.Join('.', Fields.Select(field => field.ToFullString()));
5454
}
5555

5656
public override bool Equals(object? obj)

src/JsonApiDotNetCore/Queries/Expressions/SortElementExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private string InnerToString(bool toFullString)
5959
builder.Append('-');
6060
}
6161

62-
builder.Append(toFullString ? Target.ToFullString() : Target);
62+
builder.Append(toFullString ? Target.ToFullString() : Target.ToString());
6363

6464
return builder.ToString();
6565
}

src/JsonApiDotNetCore/Queries/Expressions/SparseFieldSetExpression.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public override TResult Accept<TArgument, TResult>(QueryExpressionVisitor<TArgum
3333

3434
public override string ToString()
3535
{
36-
return string.Join(',', Fields.Select(field => field.PublicName).OrderBy(name => name));
36+
return string.Join(',', Fields.Select(field => field.ToString()).OrderBy(name => name));
3737
}
3838

3939
public override string ToFullString()
4040
{
41-
return string.Join(',', Fields.Select(field => $"{field.Type.PublicName}:{field.PublicName}").OrderBy(name => name));
41+
return string.Join(',', Fields.Select(field => $"{field.ToFullString()}").OrderBy(name => name));
4242
}
4343

4444
public override bool Equals(object? obj)

0 commit comments

Comments
 (0)