OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/browser/sessions/NSCoder+Compatibility.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 |
| 9 namespace { |
| 10 // Note: |NSNotFound| is equal to |NSIntegerMax| in 32-bit and 64-bit that |
| 11 // in turn is initialized to |LONG_MAX|. On a 32-bit build, |INT_MAX| and |
| 12 // |LONG_MAX| have the same value, however, in a 64-bit build, |LONG_MAX| |
| 13 // is much larger, so we define |NSNotFound32| to |INT_MAX| that has the |
| 14 // same value in both 32-bit and 64-bit builds. |
| 15 enum { NSNotFound32 = INT_MAX }; |
| 16 } // namespace |
| 17 |
| 18 @implementation NSCoder (Compatibility) |
| 19 |
| 20 - (NSInteger)cr_decodeIndexForKey:(NSString*)key { |
| 21 int32_t index32 = [self decodeInt32ForKey:key]; |
| 22 DCHECK(0 <= index32 && index32 <= NSNotFound32); |
| 23 return index32 == NSNotFound32 ? NSNotFound : static_cast<NSInteger>(index32); |
| 24 } |
| 25 |
| 26 - (void)cr_encodeIndex:(NSInteger)index forKey:(NSString*)key { |
| 27 DCHECK((0 <= index && index < NSNotFound32) || index == NSNotFound); |
| 28 int32_t index32 = index == NSNotFound ? static_cast<int32_t>(NSNotFound32) |
| 29 : static_cast<int32_t>(index); |
| 30 [self encodeInt32:index32 forKey:key]; |
| 31 } |
| 32 |
| 33 @end |
OLD | NEW |