Skip to content

Commit

Permalink
Added readonly modifier to fields that aren't being changed (#1610)
Browse files Browse the repository at this point in the history
Co-authored-by: Lehonti Ramos <john@doe>
  • Loading branch information
Lehonti and Lehonti Ramos authored Aug 3, 2023
1 parent 6eddc61 commit 2ebfedf
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Jint.Benchmark/DromaeoBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class DromaeoBenchmark
{"dromaeo-string-base64", null}
};

private Dictionary<string, Script> _prepared = new();
private readonly Dictionary<string, Script> _prepared = new();

private Engine engine;

Expand Down
2 changes: 1 addition & 1 deletion Jint.Benchmark/EngineConstructionBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public double BuildEngine()
var engine = new Engine();
return engine.Evaluate(_program).AsNumber();
}
}
}
8 changes: 4 additions & 4 deletions Jint.Tests/Runtime/ExtensionMethods/ObservableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ internal class Subscribe<T> : IObserver<T>
private readonly Action<Exception> onError;
private readonly Action onCompleted;

int isStopped = 0;
readonly int isStopped = 0;

public Subscribe(Action<T> onNext, Action<Exception> onError, Action onCompleted)
{
Expand Down Expand Up @@ -65,7 +65,7 @@ public static IObservable<T> Where<T>(this IObservable<T> source, Func<T, int, b

public class BaseObservable<T> : IObservable<T>
{
private List<IObserver<T>> observers = new List<IObserver<T>>();
private readonly List<IObserver<T>> observers = new List<IObserver<T>>();

public T Last { get; private set; }

Expand All @@ -78,8 +78,8 @@ public IDisposable Subscribe(IObserver<T> observer)

private class Unsubscriber : IDisposable
{
private List<IObserver<T>> _observers;
private IObserver<T> _observer;
private readonly List<IObserver<T>> _observers;
private readonly IObserver<T> _observer;

public Unsubscriber(List<IObserver<T>> observers, IObserver<T> observer)
{
Expand Down
2 changes: 1 addition & 1 deletion Jint.Tests/Runtime/GenericMethodTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void Foo<U>(U u)

public class TestGenericBaseClass<T>
{
private System.Collections.Generic.List<T> _list = new System.Collections.Generic.List<T>();
private readonly System.Collections.Generic.List<T> _list = new System.Collections.Generic.List<T>();

public int Count
{
Expand Down
2 changes: 1 addition & 1 deletion Jint.Tests/Runtime/InteropTests.MemberAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private static class EchoService

private class CustomDictionary<TValue> : IDictionary<string, TValue>
{
Dictionary<string, TValue> _dictionary = new Dictionary<string, TValue>();
readonly Dictionary<string, TValue> _dictionary = new Dictionary<string, TValue>();

public TValue this[string key]
{
Expand Down
2 changes: 1 addition & 1 deletion Jint.Tests/Runtime/JsValueConversionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Jint.Tests.Runtime
{
public class JsValueConversionTests
{
private Engine _engine;
private readonly Engine _engine;

public JsValueConversionTests()
{
Expand Down
2 changes: 1 addition & 1 deletion Jint/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Jint;
/// </summary>
internal sealed class Agent
{
private List<JsValue> _keptAlive = new();
private readonly List<JsValue> _keptAlive = new();

public void AddToKeptObjects(JsValue target)
{
Expand Down
13 changes: 8 additions & 5 deletions Jint/Native/Number/Dtoa/Bignum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal sealed class Bignum
// grow. There are no checks if the stack-allocated space is sufficient.
private const int kBigitCapacity = kMaxSignificantBits / kBigitSize;

private uint[] bigits_ = new uint[kBigitCapacity];
private readonly uint[] bigits_ = new uint[kBigitCapacity];

// The Bignum's value equals value(bigits_) * 2^(exponent_ * kBigitSize).
private int exponent_;
Expand Down Expand Up @@ -429,23 +429,26 @@ internal void MultiplyByUInt32(uint factor)
internal void MultiplyByUInt64(ulong factor)
{
if (factor == 1) return;
if (factor == 0) {
if (factor == 0)
{
Zero();
return;
}
Debug.Assert(kBigitSize < 32);
ulong carry = 0;
ulong low = factor & 0xFFFFFFFF;
ulong high = factor >> 32;
for (int i = 0; i < used_digits_; ++i) {
for (int i = 0; i < used_digits_; ++i)
{
ulong product_low = low * bigits_[i];
ulong product_high = high * bigits_[i];
ulong tmp = (carry & kBigitMask) + product_low;
bigits_[i] = (uint) (tmp & kBigitMask);
carry = (carry >> kBigitSize) + (tmp >> kBigitSize) +
(product_high << (32 - kBigitSize));
}
while (carry != 0) {
while (carry != 0)
{
EnsureCapacity(used_digits_ + 1);
bigits_[used_digits_] = (uint) (carry & kBigitMask);
used_digits_++;
Expand Down Expand Up @@ -655,4 +658,4 @@ void Square()
Clamp();
}
}
}
}
2 changes: 1 addition & 1 deletion Jint/Runtime/Interpreter/JintStatementList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private sealed class Pair

private Pair[]? _jintStatements;
private bool _initialized;
private uint _index;
private readonly uint _index;
private readonly bool _generator;

public JintStatementList(IFunction function)
Expand Down
2 changes: 1 addition & 1 deletion Jint/Runtime/Modules/CyclicModuleRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public abstract class CyclicModuleRecord : ModuleRecord
protected bool _hasTLA;
private bool _asyncEvaluation;
private PromiseCapability _topLevelCapability;
private List<CyclicModuleRecord> _asyncParentModules;
private readonly List<CyclicModuleRecord> _asyncParentModules;
private int _asyncEvalOrder;
private int _pendingAsyncDependencies;

Expand Down

0 comments on commit 2ebfedf

Please sign in to comment.