Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: lib/src/hash_sink.dart

Issue 1825983002: Avoid calling ByteData.setUint64. (Closed) Base URL: git@github.com:dart-lang/crypto.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:typed_data'; 5 import 'dart:typed_data';
6 6
7 import 'package:typed_data/typed_data.dart'; 7 import 'package:typed_data/typed_data.dart';
8 8
9 import 'digest.dart'; 9 import 'digest.dart';
10 import 'utils.dart'; 10 import 'utils.dart';
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 var lengthInBits = _lengthInBytes * bitsPerByte; 121 var lengthInBits = _lengthInBytes * bitsPerByte;
122 if (lengthInBits > maxUint64) { 122 if (lengthInBits > maxUint64) {
123 throw new UnsupportedError( 123 throw new UnsupportedError(
124 "Hashing is unsupported for messages with more than 2^64 bits."); 124 "Hashing is unsupported for messages with more than 2^64 bits.");
125 } 125 }
126 126
127 // Add the full length of the input data as a 64-bit value at the end of the 127 // Add the full length of the input data as a 64-bit value at the end of the
128 // hash. 128 // hash.
129 var offset = _pendingData.length; 129 var offset = _pendingData.length;
130 _pendingData.addAll(new Uint8List(8)); 130 _pendingData.addAll(new Uint8List(8));
131 _pendingData.buffer.asByteData().setUint64(offset, lengthInBits, _endian); 131 var byteData = _pendingData.buffer.asByteData();
132
133 // We're essentially doing byteData.setUint64(offset, lengthInBits, _endian)
134 // here, but that method isn't supported on dart2js so we implement it
135 // manually instead.
136 var highBits = lengthInBits >> 32;
sra1 2016/03/23 22:15:50 This won't actually do what you want in dart2js. d
nweiz 2016/03/23 22:21:26 Presumably in dart2js, lengthInBits can't be highe
137 var lowBits = lengthInBits & mask32;
138 if (_endian == Endianness.BIG_ENDIAN) {
139 byteData.setUint32(offset, highBits, _endian);
140 byteData.setUint32(offset + bytesPerWord, lowBits, _endian);
141 } else {
142 byteData.setUint32(offset, lowBits, _endian);
143 byteData.setUint32(offset + bytesPerWord, highBits, _endian);
144 }
132 } 145 }
133 146
134 /// Rounds [val] up to the next multiple of [n], as long as [n] is a power of 147 /// Rounds [val] up to the next multiple of [n], as long as [n] is a power of
135 /// two. 148 /// two.
136 int _roundUp(int val, int n) => (val + n - 1) & -n; 149 int _roundUp(int val, int n) => (val + n - 1) & -n;
137 } 150 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698