OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/sync/base/node_ordinal.h" | 5 #include "components/sync/base/node_ordinal.h" |
6 | 6 |
7 #include <stddef.h> | |
8 #include <stdint.h> | |
9 | |
10 #include <algorithm> | 7 #include <algorithm> |
11 #include <string> | 8 #include <string> |
12 | 9 |
13 namespace syncer { | 10 namespace syncer { |
14 | 11 |
15 NodeOrdinal Int64ToNodeOrdinal(int64_t x) { | 12 NodeOrdinal Int64ToNodeOrdinal(int64_t x) { |
16 uint64_t y = static_cast<uint64_t>(x); | 13 uint64_t y = static_cast<uint64_t>(x); |
17 y ^= 0x8000000000000000ULL; | 14 y ^= 0x8000000000000000ULL; |
18 std::string bytes(NodeOrdinal::kMinLength, '\x00'); | 15 std::string bytes(NodeOrdinal::kMinLength, '\x00'); |
19 if (y == 0) { | 16 if (y == 0) { |
(...skipping 22 matching lines...) Expand all Loading... |
42 const uint8_t byte = s[l - i - 1]; | 39 const uint8_t byte = s[l - i - 1]; |
43 y |= static_cast<uint64_t>(byte) << (i * 8); | 40 y |= static_cast<uint64_t>(byte) << (i * 8); |
44 } | 41 } |
45 y ^= 0x8000000000000000ULL; | 42 y ^= 0x8000000000000000ULL; |
46 // This is technically implementation-defined if y > INT64_MAX, so | 43 // This is technically implementation-defined if y > INT64_MAX, so |
47 // we're assuming that we're on a twos-complement machine. | 44 // we're assuming that we're on a twos-complement machine. |
48 return static_cast<int64_t>(y); | 45 return static_cast<int64_t>(y); |
49 } | 46 } |
50 | 47 |
51 } // namespace syncer | 48 } // namespace syncer |
OLD | NEW |