36e8d9ab6f
Ensure padding around data and length fields for these strings is zeroed-out, allowing for comparison to be done in word-sized chunks. For configurations where the hash is not in the header, swap the length and the hash in string class so that the length is adjacent to the data. x64 === LongStringCompare.2.3000reps 109.2% LongStringCompare.32.1000reps 526.4% LongStringCompare.1024.30reps 670.1% === ia32 === LongStringCompare.2.3000reps 90.68% LongStringCompare.32.1000reps 274.5% LongStringCompare.1024.30reps 211.4% === arm64 === LongStringCompare.2.3000reps 89.28% LongStringCompare.32.1000reps 454.5% LongStringCompare.1024.30reps 677.7% === arm === LongStringCompare.2.3000reps 68.76% LongStringCompare.32.1000reps 330.9% LongStringCompare.1024.30reps 426.8% === BUG=https://github.com/dart-lang/sdk/issues/50190 TEST=string_equals_test Change-Id: Ia4ab9bcb4daca5d4f403e0ece364bb6aafb68577 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/269600 Commit-Queue: Alexander Aprelev <aam@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com>
45 lines
1.5 KiB
Dart
45 lines
1.5 KiB
Dart
// Copyright (c) 2022, 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.
|
|
//
|
|
// Verifies that string equal implementation correctly handles strings of
|
|
// various lengths.
|
|
|
|
import 'dart:math';
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
compare(List<int> ints, String s_piece, String t_piece, bool expectedEquality) {
|
|
final s = String.fromCharCodes(ints);
|
|
String s_mid = s + s_piece + s;
|
|
String t_mid = s + t_piece + s;
|
|
Expect.isFalse(identical(s_mid, t_mid));
|
|
Expect.equals(s_mid == t_mid, expectedEquality);
|
|
String s_tail = s + s_piece;
|
|
String t_tail = s + t_piece;
|
|
Expect.isFalse(identical(s_tail, t_tail));
|
|
Expect.equals(s_tail == t_tail, expectedEquality);
|
|
String s_head = s_piece + s;
|
|
String t_head = t_piece + s;
|
|
Expect.isFalse(identical(s_head, t_head));
|
|
Expect.equals(s_head == t_head, expectedEquality);
|
|
}
|
|
|
|
main() {
|
|
const int maxStringLength = 128;
|
|
// OneByteString
|
|
for (int i = 0; i < maxStringLength; i++) {
|
|
final l = List.generate(i, (n) => (Random().nextInt(30) + 40));
|
|
compare(l, 'a', 'b', false);
|
|
compare(l, 'a', 'a', true);
|
|
}
|
|
// TwoByteString
|
|
for (int i = 0; i < maxStringLength; i++) {
|
|
final l = List.generate(i, (n) => (Random().nextInt(1024) + 1024));
|
|
compare(l, String.fromCharCodes(<int>[1042]),
|
|
String.fromCharCodes(<int>[1043]), false);
|
|
compare(l, String.fromCharCodes(<int>[1042]),
|
|
String.fromCharCodes(<int>[1042]), true);
|
|
}
|
|
}
|