dart-sdk/runtime/lib/growable_array.cc
Martin Kustermann fae934c4b1 Revert part of "[vm] Allow sharing of deeply immutable lists across isolates"
It did have noticable xx% performance regression on

  ListCopy.List.int.unmodifiable.100

TEST=ci

Issue https://github.com/dart-lang/sdk/issues/51334

Change-Id: I160d7cc98aee2e064b1767519f4b5033656ee115
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/282400
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2023-02-10 20:25:59 +00:00

96 lines
3.6 KiB
C++

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "platform/assert.h"
#include "vm/bootstrap_natives.h"
#include "vm/exceptions.h"
#include "vm/native_entry.h"
#include "vm/object.h"
#include "vm/object_graph_copy.h"
namespace dart {
DEFINE_NATIVE_ENTRY(GrowableList_allocate, 0, 2) {
const TypeArguments& type_arguments =
TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(0));
GET_NON_NULL_NATIVE_ARGUMENT(Array, data, arguments->NativeArgAt(1));
if (data.Length() < 0) {
Exceptions::ThrowRangeError("length",
Integer::Handle(Integer::New(data.Length())),
0, // This is the limit the user sees.
Array::kMaxElements);
}
const GrowableObjectArray& new_array =
GrowableObjectArray::Handle(GrowableObjectArray::New(data));
new_array.SetTypeArguments(type_arguments);
return new_array.ptr();
}
DEFINE_NATIVE_ENTRY(GrowableList_getIndexed, 0, 2) {
const GrowableObjectArray& array =
GrowableObjectArray::CheckedHandle(zone, arguments->NativeArgAt(0));
GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1));
if ((index.Value() < 0) || (index.Value() >= array.Length())) {
Exceptions::ThrowRangeError("index", index, 0, array.Length() - 1);
}
const Instance& obj = Instance::CheckedHandle(zone, array.At(index.Value()));
return obj.ptr();
}
DEFINE_NATIVE_ENTRY(GrowableList_setIndexed, 0, 3) {
const GrowableObjectArray& array =
GrowableObjectArray::CheckedHandle(zone, arguments->NativeArgAt(0));
GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1));
if ((index.Value() < 0) || (index.Value() >= array.Length())) {
Exceptions::ThrowRangeError("index", index, 0, array.Length() - 1);
}
GET_NON_NULL_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(2));
array.SetAt(index.Value(), value);
return Object::null();
}
DEFINE_NATIVE_ENTRY(GrowableList_getLength, 0, 1) {
const GrowableObjectArray& array =
GrowableObjectArray::CheckedHandle(zone, arguments->NativeArgAt(0));
return Smi::New(array.Length());
}
DEFINE_NATIVE_ENTRY(GrowableList_getCapacity, 0, 1) {
const GrowableObjectArray& array =
GrowableObjectArray::CheckedHandle(zone, arguments->NativeArgAt(0));
return Smi::New(array.Capacity());
}
DEFINE_NATIVE_ENTRY(GrowableList_setLength, 0, 2) {
const GrowableObjectArray& array =
GrowableObjectArray::CheckedHandle(zone, arguments->NativeArgAt(0));
GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(1));
ASSERT((length.Value() >= 0) && (length.Value() <= array.Capacity()));
array.SetLength(length.Value());
return Object::null();
}
DEFINE_NATIVE_ENTRY(GrowableList_setData, 0, 2) {
const GrowableObjectArray& array =
GrowableObjectArray::CheckedHandle(zone, arguments->NativeArgAt(0));
GET_NON_NULL_NATIVE_ARGUMENT(Array, data, arguments->NativeArgAt(1));
ASSERT(data.Length() >= 0);
array.SetData(data);
return Object::null();
}
DEFINE_NATIVE_ENTRY(Internal_makeListFixedLength, 0, 1) {
GET_NON_NULL_NATIVE_ARGUMENT(GrowableObjectArray, array,
arguments->NativeArgAt(0));
return Array::MakeFixedLength(array, /* unique = */ true);
}
DEFINE_NATIVE_ENTRY(Internal_makeFixedListUnmodifiable, 0, 1) {
GET_NON_NULL_NATIVE_ARGUMENT(Array, array, arguments->NativeArgAt(0));
array.MakeImmutable();
return array.ptr();
}
} // namespace dart