Skip to content

Commit

Permalink
STJ: remove redundant code, small code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
exyi committed Apr 27, 2024
1 parent 3b3a365 commit 5fa835e
Show file tree
Hide file tree
Showing 13 changed files with 6 additions and 1,023 deletions.
8 changes: 1 addition & 7 deletions src/.config/dotnet-tools.json
Expand Up @@ -13,12 +13,6 @@
"commands": [
"sign"
]
},
"dotnet-stryker": {
"version": "4.0.4",
"commands": [
"dotnet-stryker"
]
}
}
}
}
2 changes: 1 addition & 1 deletion src/Framework/Core/DotVVM.Core.csproj
Expand Up @@ -16,7 +16,7 @@
<EmbeddedResource Include="compiler\resources\**\*" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Text.Json" Version="8.0.2" />
<PackageReference Include="System.Text.Json" Version="8.0.3" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1' ">
<PackageReference Include="System.ComponentModel.Annotations" Version="4.3.0" />
Expand Down
39 changes: 0 additions & 39 deletions src/Framework/Framework/Utils/ExpressionUtils.cs
Expand Up @@ -22,45 +22,6 @@ public static Expression While(Expression condition, Expression body)
Expression.IfThenElse(condition, body, Expression.Goto(brkLabel)), brkLabel);
}

public static Expression Foreach(Expression collection, ParameterExpression item, Expression body)
{
var genericType = collection.Type.IsGenericType ? collection.Type.GetGenericArguments()[0] : typeof(object);
if (collection.Type.IsArray || collection.Type == typeof(string) || genericType == typeof(Span<>) || genericType == typeof(ReadOnlySpan<>))
return ForeachIndexer(collection, item, body);

throw new NotImplementedException();
}

static Expression ForeachIndexer(Expression collection, ParameterExpression item, Expression body)
{
var block = new List<Expression>();
var vars = new List<ParameterExpression>();
ParameterExpression collectionP;
if (collection is ParameterExpression)
collectionP = (ParameterExpression)collection;
else
{
collectionP = Expression.Parameter(collection.Type);
block.Add(Expression.Assign(collectionP, collection));
vars.Add(collectionP);
}
var indexP = Expression.Parameter(typeof(int));
vars.Add(indexP);
block.Add(Expression.Assign(indexP, Expression.Constant(0)));

var loop = While(
Expression.LessThan(indexP, Expression.Property(collectionP, "Length")),
Expression.Block(
new[] { item },
Expression.Assign(item, Index(collectionP, indexP)),
body,
Expression.PostIncrementAssign(indexP)
)
);
block.Add(loop);
return Expression.Block(vars, block);
}

static Expression Index(Expression list, Expression index)
{
if (list.Type.IsArray)
Expand Down
4 changes: 0 additions & 4 deletions src/Framework/Framework/Utils/FunctionalExtensions.cs
Expand Up @@ -104,10 +104,6 @@ public static T NotNull<T>([NotNull] this T? target, string message = "Unexpecte
where T : class =>
target ?? throw new Exception(message);

// public static T NotNull<T>([NotNull] this T? target, string message = "Unexpected null value.")
// where T : struct =>
// target ?? throw new Exception(message);

public static SortedDictionary<K, V> ToSorted<K, V>(this IDictionary<K, V> d, IComparer<K>? c = null)
where K: notnull =>
new(d, c ?? Comparer<K>.Default);
Expand Down

0 comments on commit 5fa835e

Please sign in to comment.