| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_UTILS_H_ | 28 #ifndef V8_UTILS_H_ |
| 29 #define V8_UTILS_H_ | 29 #define V8_UTILS_H_ |
| 30 | 30 |
| 31 #include <stdlib.h> | 31 #include <stdlib.h> |
| 32 #include <string.h> | 32 #include <string.h> |
| 33 #include <climits> |
| 33 | 34 |
| 34 #include "globals.h" | 35 #include "globals.h" |
| 35 #include "checks.h" | 36 #include "checks.h" |
| 36 #include "allocation.h" | 37 #include "allocation.h" |
| 37 | 38 |
| 38 namespace v8 { | 39 namespace v8 { |
| 39 namespace internal { | 40 namespace internal { |
| 40 | 41 |
| 41 // ---------------------------------------------------------------------------- | 42 // ---------------------------------------------------------------------------- |
| 42 // General helper functions | 43 // General helper functions |
| (...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 | 885 |
| 885 protected: | 886 protected: |
| 886 Vector<char> buffer_; | 887 Vector<char> buffer_; |
| 887 int position_; | 888 int position_; |
| 888 | 889 |
| 889 bool is_finalized() const { return position_ < 0; } | 890 bool is_finalized() const { return position_ < 0; } |
| 890 private: | 891 private: |
| 891 DISALLOW_IMPLICIT_CONSTRUCTORS(SimpleStringBuilder); | 892 DISALLOW_IMPLICIT_CONSTRUCTORS(SimpleStringBuilder); |
| 892 }; | 893 }; |
| 893 | 894 |
| 895 |
| 896 // A poor man's version of STL's bitset: A bit set of enums E (without explicit |
| 897 // values), fitting into an integral type T. |
| 898 template <class E, class T = int> |
| 899 class EnumSet { |
| 900 public: |
| 901 explicit EnumSet(T bits = 0) : bits_(bits) {} |
| 902 bool IsEmpty() const { return bits_ == 0; } |
| 903 bool Contains(E element) const { return (bits_ & Mask(element)) != 0; } |
| 904 void Add(E element) { bits_ |= Mask(element); } |
| 905 void Remove(E element) { bits_ &= ~Mask(element); } |
| 906 T ToIntegral() const { return bits_; } |
| 907 |
| 908 private: |
| 909 T Mask(E element) const { |
| 910 // The strange typing in ASSERT is necessary to avoid stupid warnings, see: |
| 911 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43680 |
| 912 ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT)); |
| 913 return 1 << element; |
| 914 } |
| 915 |
| 916 T bits_; |
| 917 }; |
| 918 |
| 894 } } // namespace v8::internal | 919 } } // namespace v8::internal |
| 895 | 920 |
| 896 #endif // V8_UTILS_H_ | 921 #endif // V8_UTILS_H_ |
| OLD | NEW |