Skip to content

Commit

Permalink
Memoize counts. (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
dtivel authored and goofballLogic committed Jul 11, 2018
1 parent 66f585b commit c0d3b8f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 6 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ $CLIRoot = Join-Path $RepoRoot 'cli'
$DotNetExe = Join-Path $CLIRoot 'dotnet.exe'
$NuGetExe = Join-Path $RepoRoot '.nuget\nuget.exe'


if (Test-Path $ArtifactsDir)
{
rm -r $ArtifactsDir -Force | Out-Null
}

Function Error-Log {
param(
[string]$ErrorMessage,
Expand All @@ -31,8 +37,6 @@ Function Trace-Time() {

$Global:LastTraceTime = Get-Date

rm -r $ArtifactsDir -Force | Out-Null

New-Item -ItemType Directory -Force -Path $CLIRoot | Out-Null
New-Item -ItemType Directory -Force -Path $ArtifactsDir | Out-Null

Expand Down
10 changes: 6 additions & 4 deletions src/json-ld.net/Core/JsonLdUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,16 @@ public static bool DeepCompare(JToken v1, JToken v2, bool listOrderMatters)
{
JArray l1 = (JArray)v1;
JArray l2 = (JArray)v2;
if (l1.Count != l2.Count)
var l1Count = l1.Count;
var l2Count = l2.Count;
if (l1Count != l2Count)
{
return false;
}
// used to mark members of l2 that we have already matched to avoid
// matching the same item twice for lists that have duplicates
bool[] alreadyMatched = new bool[l2.Count];
for (int i = 0; i < l1.Count; i++)
bool[] alreadyMatched = new bool[l2Count];
for (int i = 0; i < l1Count; i++)
{
JToken o1 = l1[i];
bool gotmatch = false;
Expand All @@ -105,7 +107,7 @@ public static bool DeepCompare(JToken v1, JToken v2, bool listOrderMatters)
}
else
{
for (int j = 0; j < l2.Count; j++)
for (int j = 0; j < l2Count; j++)
{
if (!alreadyMatched[j] && DeepCompare(o1, l2[j], listOrderMatters))
{
Expand Down

0 comments on commit c0d3b8f

Please sign in to comment.