Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: src/utils.h

Issue 7472029: Introduce a poor man's version of STL's bitset. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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>
Vitaly Repeshko 2011/07/21 12:56:18 We include old school standard library headers wit
Sven Panne 2011/07/21 13:07:13 That's not completely true, cstdio and cstdarg are
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 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 879
879 protected: 880 protected:
880 Vector<char> buffer_; 881 Vector<char> buffer_;
881 int position_; 882 int position_;
882 883
883 bool is_finalized() const { return position_ < 0; } 884 bool is_finalized() const { return position_ < 0; }
884 private: 885 private:
885 DISALLOW_IMPLICIT_CONSTRUCTORS(SimpleStringBuilder); 886 DISALLOW_IMPLICIT_CONSTRUCTORS(SimpleStringBuilder);
886 }; 887 };
887 888
889
890 // A poor man's version of STL's bitset: A bit set of enums E (without explicit
891 // values), fitting into an integral type T.
892 template <class E, class T = int>
893 class EnumSet {
894 public:
895 explicit EnumSet(T bits = 0) : bits_(bits) {}
896 bool IsEmpty() const { return bits_ == 0; }
897 bool Contains(E element) const { return (bits_ & Mask(element)) != 0; }
898 void Add(E element) { bits_ |= Mask(element); }
899 void Remove(E element) { bits_ &= ~Mask(element); }
900 T ToIntegral() const { return bits_; }
901
902 private:
903 T Mask(E element) const {
904 // The strange typing in ASSERT is necessary to avoid stupid warnings, see:
905 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43680
906 ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT));
907 return 1 << element;
908 }
909
910 T bits_;
911 };
912
888 } } // namespace v8::internal 913 } } // namespace v8::internal
889 914
890 #endif // V8_UTILS_H_ 915 #endif // V8_UTILS_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698