Skip to content

Commit

Permalink
Remove custom hashList(…)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasWanke committed Jun 17, 2022
1 parent ccc2828 commit 81952b0
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 37 deletions.
2 changes: 1 addition & 1 deletion lib/src/by_week_day_entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ByWeekDayEntry implements Comparable<ByWeekDayEntry> {
}

@override
int get hashCode => hashList([day, occurrence]);
int get hashCode => Object.hash(day, occurrence);

@override
bool operator ==(Object other) {
Expand Down
13 changes: 2 additions & 11 deletions lib/src/cache.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import 'package:meta/meta.dart';

import 'utils.dart';

@immutable
class CacheKey {
const CacheKey({
Expand All @@ -19,15 +17,8 @@ class CacheKey {
final bool includeBefore;

@override
int get hashCode {
return hashList([
start,
after,
includeAfter,
before,
includeBefore,
]);
}
int get hashCode =>
Object.hash(start, after, includeAfter, before, includeBefore);

@override
bool operator ==(Object other) {
Expand Down
4 changes: 1 addition & 3 deletions lib/src/codecs/string/ical.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import 'package:collection/collection.dart';
import 'package:intl/intl.dart';
import 'package:meta/meta.dart';

import '../../utils.dart';

/// Pattern corresponding to the `DATE` rule specified in
/// [RFC 5545 Section 3.3.4: Date](https://tools.ietf.org/html/rfc5545#section-3.3.4).
final iCalDatePattern = DateFormat('yyyyMMdd');
Expand Down Expand Up @@ -42,7 +40,7 @@ class ICalProperty {
final String value;

@override
int get hashCode => hashList([name, parameters, value]);
int get hashCode => Object.hash(name, parameters, value);
@override
bool operator ==(Object other) {
if (identical(this, other)) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/recurrence_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class RecurrenceRule {

@override
int get hashCode {
return hashList([
return Object.hash(
frequency,
until,
count,
Expand All @@ -259,7 +259,7 @@ class RecurrenceRule {
byWeeks,
byMonths,
bySetPositions,
]);
);
}

@override
Expand Down
19 changes: 0 additions & 19 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,6 @@ import 'package:time/time.dart';

export 'utils/week.dart';

/// Combines the [Object.hashCode] values of an arbitrary number of objects
/// from an [Iterable] into one value. This function will return the same
/// value if given `null` as if given an empty list.
// Borrowed from dart:ui.
int hashList(Iterable<Object?>? arguments) {
var result = 0;
if (arguments != null) {
for (final argument in arguments) {
var hash = result;
hash = 0x1fffffff & (hash + argument.hashCode);
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
result = hash ^ (hash >> 6);
}
}
result = 0x1fffffff & (result + ((0x03ffffff & result) << 3));
result = result ^ (result >> 11);
return 0x1fffffff & (result + ((0x00003fff & result) << 15));
}

extension DateTimeRrule on DateTime {
DateTime copyWith({
int? year,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils/week.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class WeekInfo implements Comparable<WeekInfo> {
}

@override
int get hashCode => hashList([weekBasedYear, weekOfYear]);
int get hashCode => Object.hash(weekBasedYear, weekOfYear);

@override
bool operator ==(Object other) {
Expand Down

0 comments on commit 81952b0

Please sign in to comment.