Skip to content

Commit

Permalink
small optimizations for array
Browse files Browse the repository at this point in the history
  • Loading branch information
nilproject committed Jun 17, 2024
1 parent d184d9d commit a518a9d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
8 changes: 5 additions & 3 deletions NiL.JS/BaseLibrary/Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ internal bool SetLength(long nlen)

if (_data.Length != nlen)
{
_data.TrimLength();
if (_data.Length > nlen)
_data.TrimLength();

_data[(int)nlen - 1] = _data[(int)nlen - 1];
}

Expand Down Expand Up @@ -1237,7 +1239,7 @@ public static JSValue push(JSValue self, Arguments args)
var v = args[i];

tempKey._iValue = i;
var parentProp = selfa.GetProperty(tempKey, false, PropertyScope.Super);
var parentProp = selfa.__proto__?.GetProperty(tempKey, false, PropertyScope.Common);
if (parentProp is null or not { _valueType: JSValueType.Property })
selfa._data.Add(v.CloneImpl(false));
else
Expand Down Expand Up @@ -2307,7 +2309,7 @@ internal protected override JSValue GetProperty(JSValue key, bool forWrite, Prop
{
notExists._valueType = JSValueType.NotExistsInObject;
res = notExists;
if (res._valueType < JSValueType.Undefined && memberScope != PropertyScope.Own)
if (memberScope != PropertyScope.Own)
{
return __proto__.GetProperty(key, false, memberScope);
}
Expand Down
21 changes: 12 additions & 9 deletions NiL.JS/Core/Interop/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ internal protected override JSValue GetProperty(JSValue key, bool forWrite, Prop
}

IList<MemberInfo> m = null;
_members.TryGetValue(name, out m);
if (key._valueType is not JSValueType.Integer and not JSValueType.Double)
_members.TryGetValue(name, out m);

if (m == null || m.Count == 0)
{
Expand All @@ -372,9 +373,6 @@ internal protected override JSValue GetProperty(JSValue key, bool forWrite, Prop
else
property = base.GetProperty(key, forWrite && !_indexersSupported, memberScope);

if (!_indexersSupported)
return property;

if (property.Exists)
{
if (forWrite)
Expand All @@ -392,12 +390,17 @@ internal protected override JSValue GetProperty(JSValue key, bool forWrite, Prop
return property;
}

var args = new Arguments { null, key };
return new JSValue
if (_indexersSupported)
{
_valueType = JSValueType.Property,
_oValue = new PropertyPair(_indexerProperty.getter.bind(args), _indexerProperty.setter.bind(args))
};
var args = new Arguments { null, key };
return new JSValue
{
_valueType = JSValueType.Property,
_oValue = new PropertyPair(_indexerProperty.getter.bind(args), _indexerProperty.setter.bind(args))
};
}
else
return property;
}

var result = proxyMember(m);
Expand Down

0 comments on commit a518a9d

Please sign in to comment.