Skip to content

Commit

Permalink
Remove Enum.HasFlag usage (#1850)
Browse files Browse the repository at this point in the history
* cleanup Array capacity usage
  • Loading branch information
lahma authored May 3, 2024
1 parent 6e28401 commit dadeb15
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 41 deletions.
1 change: 0 additions & 1 deletion Jint/Native/Array/ArrayOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,6 @@ public override void CreateDataPropertyOrThrow(ulong index, JsValue value)

public override void Set(ulong index, JsValue value, bool updateLength = false, bool throwOnError = true)
{
EnsureCapacity(index + 1);
_target.SetAt((int)index, value);
}

Expand Down
7 changes: 6 additions & 1 deletion Jint/Native/Array/ArrayPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,12 @@ private JsValue Unshift(JsValue thisObject, JsValue[] arguments)
ExceptionHelper.ThrowTypeError(_realm, "Invalid array length");
}

o.EnsureCapacity(len + argCount);
// only prepare for larger if we cannot rely on default growth algorithm
if (len + argCount > 2 * len)
{
o.EnsureCapacity(len + argCount);
}

var minIndex = o.GetSmallestIndex(len);
for (var k = len; k > minIndex; k--)
{
Expand Down
37 changes: 1 addition & 36 deletions Jint/Runtime/Descriptors/PropertyDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public bool IsAccessorDescriptor()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool IsDataDescriptor()
{
if (_flags.HasFlag(PropertyFlag.NonData))
if ((_flags & PropertyFlag.NonData) != PropertyFlag.None)
{
return false;
}
Expand All @@ -415,41 +415,6 @@ public bool IsGenericDescriptor()
return !IsDataDescriptor() && !IsAccessorDescriptor();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal bool TryGetValue(ObjectInstance thisArg, out JsValue value)
{
value = JsValue.Undefined;

// IsDataDescriptor logic inlined
if ((_flags & (PropertyFlag.WritableSet | PropertyFlag.Writable)) != PropertyFlag.None)
{
var val = (_flags & PropertyFlag.CustomJsValue) != PropertyFlag.None
? CustomValue
: _value;

if (!ReferenceEquals(val, null))
{
value = val;
return true;
}
}

if (this == Undefined)
{
return false;
}

var getter = Get;
if (!ReferenceEquals(getter, null) && !getter.IsUndefined())
{
// if getter is not undefined it must be ICallable
var callable = (ICallable) getter;
value = callable.Call(thisArg, Arguments.Empty);
}

return true;
}

private sealed class UndefinedPropertyDescriptor : PropertyDescriptor
{
public UndefinedPropertyDescriptor() : base(PropertyFlag.None | PropertyFlag.CustomJsValue)
Expand Down
2 changes: 1 addition & 1 deletion Jint/Runtime/Interop/ObjectWrapper.Specialized.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void SetAt(int index, JsValue value)
{
if (_engine.Options.Interop.AllowWrite)
{
EnsureCapacity(index);
EnsureCapacity(index + 1);
DoSetAt(index, ConvertToItemType(value));
}
}
Expand Down
2 changes: 1 addition & 1 deletion Jint/Runtime/Interop/Reflection/FieldAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public FieldAccessor(FieldInfo fieldInfo, PropertyInfo? indexer = null)
_fieldInfo = fieldInfo;
}

public override bool Writable => !_fieldInfo.Attributes.HasFlag(FieldAttributes.InitOnly);
public override bool Writable => (_fieldInfo.Attributes & FieldAttributes.InitOnly) == (FieldAttributes) 0;

protected override object? DoGetValue(object target, string memberName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public JintYieldExpression(YieldExpression expression) : base(expression)

protected override object EvaluateInternal(EvaluationContext context)
{
if (!context.Engine.Options.ExperimentalFeatures.HasFlag(ExperimentalFeature.Generators))
if ((context.Engine.Options.ExperimentalFeatures & ExperimentalFeature.Generators) == ExperimentalFeature.None)
{
ExceptionHelper.ThrowJavaScriptException(
context.Engine.Intrinsics.Error,
Expand Down

0 comments on commit dadeb15

Please sign in to comment.