mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
This moves some files out of shared that are not actually shared
with isomorphic. They're specific to the renderers.
(cherry picked from commit 4bc1048e0d)
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
/**
|
|
* Copyright 2013-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
* @providesModule adler32
|
|
* @flow
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
var MOD = 65521;
|
|
|
|
// adler32 is not cryptographically strong, and is only used to sanity check that
|
|
// markup generated on the server matches the markup generated on the client.
|
|
// This implementation (a modified version of the SheetJS version) has been optimized
|
|
// for our use case, at the expense of conforming to the adler32 specification
|
|
// for non-ascii inputs.
|
|
function adler32(data: string): number {
|
|
var a = 1;
|
|
var b = 0;
|
|
var i = 0;
|
|
var l = data.length;
|
|
var m = l & ~0x3;
|
|
while (i < m) {
|
|
var n = Math.min(i + 4096, m);
|
|
for (; i < n; i += 4) {
|
|
b += (
|
|
(a += data.charCodeAt(i)) +
|
|
(a += data.charCodeAt(i + 1)) +
|
|
(a += data.charCodeAt(i + 2)) +
|
|
(a += data.charCodeAt(i + 3))
|
|
);
|
|
}
|
|
a %= MOD;
|
|
b %= MOD;
|
|
}
|
|
for (; i < l; i++) {
|
|
b += (a += data.charCodeAt(i));
|
|
}
|
|
a %= MOD;
|
|
b %= MOD;
|
|
return a | (b << 16);
|
|
}
|
|
|
|
module.exports = adler32;
|