mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 01:45:06 +00:00
6505994d58
Change-Id: I3f02d584d30fc7a2f3bd93858eaf77abe3c9f5b7 Reviewed-on: https://dart-review.googlesource.com/17720 Reviewed-by: Vyacheslav Egorov <vegorov@google.com> Commit-Queue: Alexander Markov <alexmarkov@google.com>
69 lines
2.3 KiB
Dart
69 lines
2.3 KiB
Dart
// 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.
|
|
|
|
// part of "core_patch.dart";
|
|
|
|
int _getHash(obj) native "Object_getHash";
|
|
void _setHash(obj, hash) native "Object_setHash";
|
|
|
|
@patch
|
|
class Object {
|
|
// The VM has its own implementation of equals.
|
|
@patch
|
|
bool operator ==(other) native "Object_equals";
|
|
|
|
// Helpers used to implement hashCode. If a hashCode is used, we remember it
|
|
// in a weak table in the VM (32 bit) or in the header of the object (64
|
|
// bit). A new hashCode value is calculated using a random number generator.
|
|
static final _hashCodeRnd = new Random();
|
|
|
|
static int _objectHashCode(obj) {
|
|
var result = _getHash(obj);
|
|
if (result == 0) {
|
|
// We want the hash to be a Smi value greater than 0.
|
|
result = _hashCodeRnd.nextInt(0x40000000);
|
|
do {
|
|
result = _hashCodeRnd.nextInt(0x40000000);
|
|
} while (result == 0);
|
|
_setHash(obj, result);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
@patch
|
|
int get hashCode => _objectHashCode(this);
|
|
int get _identityHashCode => _objectHashCode(this);
|
|
|
|
@patch
|
|
String toString() native "Object_toString";
|
|
// A statically dispatched version of Object.toString.
|
|
static String _toString(obj) native "Object_toString";
|
|
|
|
@patch
|
|
dynamic noSuchMethod(Invocation invocation) {
|
|
// TODO(regis): Remove temp constructor identifier 'withInvocation'.
|
|
throw new NoSuchMethodError.withInvocation(this, invocation);
|
|
}
|
|
|
|
@patch
|
|
Type get runtimeType native "Object_runtimeType";
|
|
|
|
static bool _haveSameRuntimeType(a, b) native "Object_haveSameRuntimeType";
|
|
|
|
// Call this function instead of inlining instanceof, thus collecting
|
|
// type feedback and reducing code size of unoptimized code.
|
|
bool _instanceOf(instantiatorTypeArguments, functionTypeArguments, type)
|
|
native "Object_instanceOf";
|
|
|
|
// Group of functions for implementing fast simple instance of.
|
|
bool _simpleInstanceOf(type) native "Object_simpleInstanceOf";
|
|
bool _simpleInstanceOfTrue(type) => true;
|
|
bool _simpleInstanceOfFalse(type) => false;
|
|
|
|
// Call this function instead of inlining 'as', thus collecting type
|
|
// feedback. Returns receiver.
|
|
_as(instantiatorTypeArguments, functionTypeArguments, type)
|
|
native "Object_as";
|
|
}
|