Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Sep 1, 2024
1 parent ef996da commit dddb178
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 2 deletions.
2 changes: 1 addition & 1 deletion YantraJS.Core.Tests/YantraJS.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
4 changes: 4 additions & 0 deletions YantraJS.Core/Core/Array/JSArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ internal IElementEnumerator GetEntries()

public JSArray(uint count): this()
{
AllocateElements(count);
CreateElements(count);
_length = count;
}
Expand Down Expand Up @@ -122,6 +123,9 @@ public double ArrayLength
{
elements.RemoveAt(i);
}
} else
{
elements.Resize(this._length);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions YantraJS.Core/Core/Object/JSObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ public ref SAUint32Map<JSProperty> GetSymbols()
return ref symbols;
}

internal void AllocateElements(uint size)
{
size = size > 1024 ? 1024 : size;
elements.Resize(size);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal ref ElementArray CreateElements(uint size = 4)
{
Expand Down
18 changes: 18 additions & 0 deletions YantraJS.Core/Core/Storage/SAUint32Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,24 @@ private ref Node GetNode(uint originalKey, bool create = false)
return ref Empty;
}

internal void Resize(int size)
{
if (size < 0)
{
return;
}
// right align to 4 bits..
size = ((size / 4)+1)*4;
if (storage == null)
{
storage = new Node[size];
return;
}
if (this.storage.Length < size)
{
Array.Resize(ref storage, size);
}
}
}


Expand Down
7 changes: 7 additions & 0 deletions YantraJS.Core/Core/Storage/UIntMapArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,13 @@ public bool HasKey(uint key)
return Storage.HasKey(key);
}

public void Resize(uint size)
{
if (length <= size)
{
Storage.Resize((int)size);
}
}

// PRIVATE IMPLEMENTATION METHODS
//_________________________________________________________________________________________
Expand Down
46 changes: 46 additions & 0 deletions YantraJS.Core/Core/Storage/VirtualMemory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace YantraJS.Core.Core.Storage
{
public class VirtualMemory<T>
{

private T[] nodes = null;
private int last = 0;

private int count = 0;

public void Allocate(int length)
{
if (this.count <= length)
{
// we need to resize...
var max = this.count * 2;
if (this.count * 2 > length)
{
length = this.count * 2;
}
this.SetCapacity(length);
}
}


}

public readonly struct VirtualSpan<T>
{
private readonly T[] nodes;
private readonly int offset;
public readonly int Length;

public ref T this[int index]
{
get
{
return ref nodes[offset + index];
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>

<RootNamespace>YantraJS</RootNamespace>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit dddb178

Please sign in to comment.