Skip to content

Commit 824028f

Browse files
alexmarkovCommit Queue
authored and
Commit Queue
committed
[vm] Move _Record class to record_patch.dart
TEST=ci Issue: #49719 Change-Id: Ibf818df1f57afa93051123d0c9493913e7f9ab76 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260641 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent c427299 commit 824028f

File tree

5 files changed

+96
-89
lines changed

5 files changed

+96
-89
lines changed

sdk/lib/_internal/vm/lib/core_patch.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import "dart:typed_data"
8484
// part "map_patch.dart";
8585
// part "null_patch.dart";
8686
// part "object_patch.dart";
87+
// part "record_patch.dart";
8788
// part "regexp_patch.dart";
8889
// part "stacktrace.dart";
8990
// part "stopwatch_patch.dart";

sdk/lib/_internal/vm/lib/object_patch.dart

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -83,92 +83,3 @@ String _objectToString(Object? obj) => obj.toString();
8383
@pragma("vm:entry-point", "call")
8484
dynamic _objectNoSuchMethod(Object? obj, Invocation invocation) =>
8585
obj.noSuchMethod(invocation);
86-
87-
// Base class for record instances.
88-
// TODO(dartbug.com/49719): create a separate patch file for this class.
89-
@pragma("vm:entry-point")
90-
class _Record {
91-
factory _Record._uninstantiable() {
92-
throw "Unreachable";
93-
}
94-
95-
// Do not inline to avoid mixing _fieldAt with
96-
// record field accesses.
97-
@pragma("vm:never-inline")
98-
bool operator ==(Object other) {
99-
if (identical(this, other)) {
100-
return true;
101-
}
102-
103-
if (other is! _Record) {
104-
return false;
105-
}
106-
107-
_Record otherRec = unsafeCast<_Record>(other);
108-
final int numFields = _numFields;
109-
if (numFields != otherRec._numFields ||
110-
!identical(_fieldNames, otherRec._fieldNames)) {
111-
return false;
112-
}
113-
114-
for (int i = 0; i < numFields; ++i) {
115-
if (_fieldAt(i) != otherRec._fieldAt(i)) {
116-
return false;
117-
}
118-
}
119-
return true;
120-
}
121-
122-
// Do not inline to avoid mixing _fieldAt with
123-
// record field accesses.
124-
@pragma("vm:never-inline")
125-
int get hashCode {
126-
final int numFields = _numFields;
127-
int hash = numFields;
128-
hash = SystemHash.combine(hash, identityHashCode(_fieldNames));
129-
for (int i = 0; i < numFields; ++i) {
130-
hash = SystemHash.combine(hash, _fieldAt(i).hashCode);
131-
}
132-
return SystemHash.finish(hash);
133-
}
134-
135-
// Do not inline to avoid mixing _fieldAt with
136-
// record field accesses.
137-
@pragma("vm:never-inline")
138-
String toString() {
139-
StringBuffer buffer = StringBuffer("(");
140-
final int numFields = _numFields;
141-
final _List fieldNames = _fieldNames;
142-
final int numPositionalFields = numFields - fieldNames.length;
143-
for (int i = 0; i < numFields; ++i) {
144-
if (i != 0) {
145-
buffer.write(", ");
146-
}
147-
if (i >= numPositionalFields) {
148-
buffer.write(unsafeCast<String>(fieldNames[i - numPositionalFields]));
149-
buffer.write(": ");
150-
}
151-
buffer.write(_fieldAt(i).toString());
152-
}
153-
buffer.write(")");
154-
return buffer.toString();
155-
}
156-
157-
@pragma("vm:recognized", "other")
158-
@pragma("vm:prefer-inline")
159-
external int get _numFields;
160-
161-
@pragma("vm:recognized", "other")
162-
@pragma("vm:prefer-inline")
163-
external _List get _fieldNames;
164-
165-
// Currently compiler does not take into account aliasing
166-
// between access to record fields via _fieldAt and
167-
// via record.foo / record.$n.
168-
// So this method should only be used in methods
169-
// which only access record fields with _fieldAt and
170-
// annotated with @pragma("vm:never-inline").
171-
@pragma("vm:recognized", "other")
172-
@pragma("vm:prefer-inline")
173-
external Object? _fieldAt(int index);
174-
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// part of "core_patch.dart";
6+
7+
// Base class for record instances.
8+
@pragma("vm:entry-point")
9+
class _Record {
10+
factory _Record._uninstantiable() {
11+
throw "Unreachable";
12+
}
13+
14+
// Do not inline to avoid mixing _fieldAt with
15+
// record field accesses.
16+
@pragma("vm:never-inline")
17+
bool operator ==(Object other) {
18+
if (identical(this, other)) {
19+
return true;
20+
}
21+
22+
if (other is! _Record) {
23+
return false;
24+
}
25+
26+
_Record otherRec = unsafeCast<_Record>(other);
27+
final int numFields = _numFields;
28+
if (numFields != otherRec._numFields ||
29+
!identical(_fieldNames, otherRec._fieldNames)) {
30+
return false;
31+
}
32+
33+
for (int i = 0; i < numFields; ++i) {
34+
if (_fieldAt(i) != otherRec._fieldAt(i)) {
35+
return false;
36+
}
37+
}
38+
return true;
39+
}
40+
41+
// Do not inline to avoid mixing _fieldAt with
42+
// record field accesses.
43+
@pragma("vm:never-inline")
44+
int get hashCode {
45+
final int numFields = _numFields;
46+
int hash = numFields;
47+
hash = SystemHash.combine(hash, identityHashCode(_fieldNames));
48+
for (int i = 0; i < numFields; ++i) {
49+
hash = SystemHash.combine(hash, _fieldAt(i).hashCode);
50+
}
51+
return SystemHash.finish(hash);
52+
}
53+
54+
// Do not inline to avoid mixing _fieldAt with
55+
// record field accesses.
56+
@pragma("vm:never-inline")
57+
String toString() {
58+
StringBuffer buffer = StringBuffer("(");
59+
final int numFields = _numFields;
60+
final _List fieldNames = _fieldNames;
61+
final int numPositionalFields = numFields - fieldNames.length;
62+
for (int i = 0; i < numFields; ++i) {
63+
if (i != 0) {
64+
buffer.write(", ");
65+
}
66+
if (i >= numPositionalFields) {
67+
buffer.write(unsafeCast<String>(fieldNames[i - numPositionalFields]));
68+
buffer.write(": ");
69+
}
70+
buffer.write(_fieldAt(i).toString());
71+
}
72+
buffer.write(")");
73+
return buffer.toString();
74+
}
75+
76+
@pragma("vm:recognized", "other")
77+
@pragma("vm:prefer-inline")
78+
external int get _numFields;
79+
80+
@pragma("vm:recognized", "other")
81+
@pragma("vm:prefer-inline")
82+
external _List get _fieldNames;
83+
84+
// Currently compiler does not take into account aliasing
85+
// between access to record fields via _fieldAt and
86+
// via record.foo / record.$n.
87+
// So this method should only be used in methods
88+
// which only access record fields with _fieldAt and
89+
// annotated with @pragma("vm:never-inline").
90+
@pragma("vm:recognized", "other")
91+
@pragma("vm:prefer-inline")
92+
external Object? _fieldAt(int index);
93+
}

sdk/lib/libraries.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"_internal/vm/lib/map_patch.dart",
6565
"_internal/vm/lib/null_patch.dart",
6666
"_internal/vm/lib/object_patch.dart",
67+
"_internal/vm/lib/record_patch.dart",
6768
"_internal/vm/lib/regexp_patch.dart",
6869
"_internal/vm/lib/stacktrace.dart",
6970
"_internal/vm/lib/stopwatch_patch.dart",

sdk/lib/libraries.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ vm_common:
7171
- "_internal/vm/lib/map_patch.dart"
7272
- "_internal/vm/lib/null_patch.dart"
7373
- "_internal/vm/lib/object_patch.dart"
74+
- "_internal/vm/lib/record_patch.dart"
7475
- "_internal/vm/lib/regexp_patch.dart"
7576
- "_internal/vm/lib/stacktrace.dart"
7677
- "_internal/vm/lib/stopwatch_patch.dart"

0 commit comments

Comments
 (0)