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

Side by Side Diff: src/unicode.h

Issue 700963002: Replace C++ bitfields with our own BitFields (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fixed AST node field sizes; more scanner fixes; undid hydrogen.h/cc changes Created 6 years, 1 month 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 | « src/scanner.cc ('k') | src/unicode-inl.h » ('j') | 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 // 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 #ifndef V8_UNICODE_H_ 5 #ifndef V8_UNICODE_H_
6 #define V8_UNICODE_H_ 6 #define V8_UNICODE_H_
7 7
8 #include <sys/types.h> 8 #include <sys/types.h>
9 #include "src/globals.h" 9 #include "src/globals.h"
10 #include "src/utils.h"
10 /** 11 /**
11 * \file 12 * \file
12 * Definitions and convenience functions for working with unicode. 13 * Definitions and convenience functions for working with unicode.
13 */ 14 */
14 15
15 namespace unibrow { 16 namespace unibrow {
16 17
17 typedef unsigned int uchar; 18 typedef unsigned int uchar;
18 typedef unsigned char byte; 19 typedef unsigned char byte;
19 20
20 /** 21 /**
21 * The max length of the result of converting the case of a single 22 * The max length of the result of converting the case of a single
22 * character. 23 * character.
23 */ 24 */
24 const int kMaxMappingSize = 4; 25 const int kMaxMappingSize = 4;
25 26
26 template <class T, int size = 256> 27 template <class T, int size = 256>
27 class Predicate { 28 class Predicate {
28 public: 29 public:
29 inline Predicate() { } 30 inline Predicate() { }
30 inline bool get(uchar c); 31 inline bool get(uchar c);
32
31 private: 33 private:
32 friend class Test; 34 friend class Test;
33 bool CalculateValue(uchar c); 35 bool CalculateValue(uchar c);
34 struct CacheEntry { 36 class CacheEntry {
35 inline CacheEntry() : code_point_(0), value_(0) { } 37 public:
38 inline CacheEntry()
39 : bit_field_(CodePointField::encode(0) | ValueField::encode(0)) {}
36 inline CacheEntry(uchar code_point, bool value) 40 inline CacheEntry(uchar code_point, bool value)
37 : code_point_(code_point), 41 : bit_field_(CodePointField::encode(code_point) |
38 value_(value) { } 42 ValueField::encode(value)) {}
39 uchar code_point_ : 21; 43
40 bool value_ : 1; 44 uchar code_point() const { return CodePointField::decode(bit_field_); }
45 bool value() const { return ValueField::decode(bit_field_); }
46
47 private:
48 class CodePointField : public v8::internal::BitField<uchar, 0, 21> {};
49 class ValueField : public v8::internal::BitField<bool, 21, 1> {};
50
51 uint32_t bit_field_;
41 }; 52 };
42 static const int kSize = size; 53 static const int kSize = size;
43 static const int kMask = kSize - 1; 54 static const int kMask = kSize - 1;
44 CacheEntry entries_[kSize]; 55 CacheEntry entries_[kSize];
45 }; 56 };
46 57
47 58
48 // A cache used in case conversion. It caches the value for characters 59 // A cache used in case conversion. It caches the value for characters
49 // that either have no mapping or map to a single character independent 60 // that either have no mapping or map to a single character independent
50 // of context. Characters that map to more than one character or that 61 // of context. Characters that map to more than one character or that
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 static const int kMaxWidth = 1; 216 static const int kMaxWidth = 1;
206 static int Convert(uchar c, 217 static int Convert(uchar c,
207 uchar n, 218 uchar n,
208 uchar* result, 219 uchar* result,
209 bool* allow_caching_ptr); 220 bool* allow_caching_ptr);
210 }; 221 };
211 222
212 } // namespace unibrow 223 } // namespace unibrow
213 224
214 #endif // V8_UNICODE_H_ 225 #endif // V8_UNICODE_H_
OLDNEW
« no previous file with comments | « src/scanner.cc ('k') | src/unicode-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698