From 888f4f5045d89b1eb126ef1a3db8b059135f9602 Mon Sep 17 00:00:00 2001 From: Miller Adulu Date: Fri, 19 Mar 2021 19:54:39 +0300 Subject: [PATCH] Remove custom util implementation in favor of quiver --- lib/models/documents/attribute.dart | 3 +-- lib/models/documents/style.dart | 5 ++--- lib/models/quill_delta.dart | 9 ++++----- lib/utils/hashcode.dart | 31 ----------------------------- 4 files changed, 7 insertions(+), 41 deletions(-) delete mode 100644 lib/utils/hashcode.dart diff --git a/lib/models/documents/attribute.dart b/lib/models/documents/attribute.dart index a39306e6..3c90fa75 100644 --- a/lib/models/documents/attribute.dart +++ b/lib/models/documents/attribute.dart @@ -1,4 +1,3 @@ -import 'package:flutter_quill/utils/hashcode.dart' as hashcode; import 'package:quiver/core.dart'; enum AttributeScope { @@ -185,7 +184,7 @@ class Attribute { } @override - int get hashCode => hashcode.hash3(key, scope, value); + int get hashCode => hash3(key, scope, value); @override String toString() { diff --git a/lib/models/documents/style.dart b/lib/models/documents/style.dart index 7daa77dc..7f7391b2 100644 --- a/lib/models/documents/style.dart +++ b/lib/models/documents/style.dart @@ -1,6 +1,5 @@ import 'package:collection/collection.dart'; import 'package:flutter_quill/models/documents/attribute.dart'; -import 'package:flutter_quill/utils/hashcode.dart' as hashcode; import 'package:quiver/core.dart'; /* Collection of style attributes */ @@ -102,8 +101,8 @@ class Style { @override int get hashCode { final hashes = _attributes.entries - .map((entry) => hashcode.hash2(entry.key, entry.value)); - return hashcode.hashObjects(hashes); + .map((entry) => hash2(entry.key, entry.value)); + return hashObjects(hashes); } @override diff --git a/lib/models/quill_delta.dart b/lib/models/quill_delta.dart index 9349203f..c27cfce0 100644 --- a/lib/models/quill_delta.dart +++ b/lib/models/quill_delta.dart @@ -7,7 +7,6 @@ library quill_delta; import 'dart:math' as math; import 'package:collection/collection.dart'; -import 'package:flutter_quill/utils/hashcode.dart' as hashcode; import 'package:quiver/core.dart'; const _attributeEquality = DeepCollectionEquality(); @@ -155,11 +154,11 @@ class Operation { @override int get hashCode { if (_attributes != null && _attributes!.isNotEmpty) { - final attrsHash = hashcode.hashObjects( - _attributes!.entries.map((e) => hashcode.hash2(e.key, e.value))); - return hashcode.hash3(key, value, attrsHash); + final attrsHash = hashObjects( + _attributes!.entries.map((e) => hash2(e.key, e.value))); + return hash3(key, value, attrsHash); } - return hashcode.hash2(key, value); + return hash2(key, value); } @override diff --git a/lib/utils/hashcode.dart b/lib/utils/hashcode.dart deleted file mode 100644 index 38b51ce5..00000000 --- a/lib/utils/hashcode.dart +++ /dev/null @@ -1,31 +0,0 @@ -library quiver.hashcode; - -/// Generates a hash code for multiple [objects]. -int hashObjects(Iterable objects) => - _finish(objects.fold(0, (h, i) => _combine(h, i.hashCode))); - -/// Generates a hash code for two objects. -int hash2(a, b) => _finish(_combine(_combine(0, a.hashCode), b.hashCode)); - -/// Generates a hash code for three objects. -int hash3(a, b, c) => _finish( - _combine(_combine(_combine(0, a.hashCode), b.hashCode), c.hashCode)); - -/// Generates a hash code for four objects. -int hash4(a, b, c, d) => _finish(_combine( - _combine(_combine(_combine(0, a.hashCode), b.hashCode), c.hashCode), - d.hashCode)); - -// Jenkins hash functions - -int _combine(int hash, int value) { - hash = 0x1fffffff & (hash + value); - hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10)); - return hash ^ (hash >> 6); -} - -int _finish(int hash) { - hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); - hash = hash ^ (hash >> 11); - return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); -}