| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2012 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef BitArray_h | 26 #ifndef BitArray_h |
| 27 #define BitArray_h | 27 #define BitArray_h |
| 28 | 28 |
| 29 #include "wtf/Assertions.h" | 29 #include "wtf/Assertions.h" |
| 30 #include <string.h> | 30 #include <string.h> |
| 31 | 31 |
| 32 namespace WTF { | 32 namespace WTF { |
| 33 | 33 |
| 34 template<unsigned arraySize> | 34 template <unsigned arraySize> |
| 35 class BitArray { | 35 class BitArray { |
| 36 public: | 36 public: |
| 37 BitArray(bool value = false) | 37 BitArray(bool value = false) { |
| 38 { | 38 memset(m_data, value ? 0xFF : 0, sizeof(m_data)); |
| 39 memset(m_data, value ? 0xFF : 0, sizeof(m_data)); | 39 } |
| 40 } | |
| 41 | 40 |
| 42 void set(unsigned index) | 41 void set(unsigned index) { |
| 43 { | 42 ASSERT_WITH_SECURITY_IMPLICATION(index < arraySize); |
| 44 ASSERT_WITH_SECURITY_IMPLICATION(index < arraySize); | 43 m_data[index / 8] |= 1 << (index & 7); |
| 45 m_data[index / 8] |= 1 << (index & 7); | 44 } |
| 46 } | |
| 47 | 45 |
| 48 void clear(unsigned index) | 46 void clear(unsigned index) { |
| 49 { | 47 ASSERT_WITH_SECURITY_IMPLICATION(index < arraySize); |
| 50 ASSERT_WITH_SECURITY_IMPLICATION(index < arraySize); | 48 m_data[index / 8] &= ~(1 << (index & 7)); |
| 51 m_data[index / 8] &= ~(1 << (index & 7)); | 49 } |
| 52 } | |
| 53 | 50 |
| 54 bool get(unsigned index) const | 51 bool get(unsigned index) const { |
| 55 { | 52 ASSERT_WITH_SECURITY_IMPLICATION(index < arraySize); |
| 56 ASSERT_WITH_SECURITY_IMPLICATION(index < arraySize); | 53 return !!(m_data[index / 8] & (1 << (index & 7))); |
| 57 return !!(m_data[index / 8] & (1 << (index & 7))); | 54 } |
| 58 } | |
| 59 | 55 |
| 60 private: | 56 private: |
| 61 unsigned char m_data[arraySize / 8 + 1]; | 57 unsigned char m_data[arraySize / 8 + 1]; |
| 62 }; | 58 }; |
| 63 | 59 |
| 64 } // namespace WTF | 60 } // namespace WTF |
| 65 | 61 |
| 66 using WTF::BitArray; | 62 using WTF::BitArray; |
| 67 | 63 |
| 68 #endif // BitArray_h | 64 #endif // BitArray_h |
| OLD | NEW |