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

Side by Side Diff: src/jsregexp.h

Issue 10408: Uniqueify out sets. (Closed)
Patch Set: Created 12 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
« no previous file with comments | « no previous file | src/jsregexp.cc » ('j') | test/cctest/test-regexp.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 DoForEach<typename ZoneSplayTree<Config>::Node, Callback>(root_, c); 261 DoForEach<typename ZoneSplayTree<Config>::Node, Callback>(root_, c);
262 } 262 }
263 263
264 private: 264 private:
265 Node* root_; 265 Node* root_;
266 }; 266 };
267 267
268 268
269 // A set of unsigned integers that behaves especially well on small 269 // A set of unsigned integers that behaves especially well on small
270 // integers (< 32). May do zone-allocation. 270 // integers (< 32). May do zone-allocation.
271 class OutSet { 271 class OutSet: public ZoneObject {
272 public: 272 public:
273 OutSet() : first_(0), remaining_(NULL) { } 273 OutSet() : first_(0), remaining_(NULL), successors_(NULL) { }
274 explicit inline OutSet(unsigned value); 274 OutSet* Extend(unsigned value);
275 static inline OutSet empty() { return OutSet(); }
276 void Set(unsigned value);
277 bool Get(unsigned value); 275 bool Get(unsigned value);
278 OutSet Clone();
279 static const unsigned kFirstLimit = 32; 276 static const unsigned kFirstLimit = 32;
280 private: 277 private:
278
279 // Destructively set a value in this set. In most cases you want
280 // to use Extend instead to ensure that only one instance exists
281 // that contains the same values.
282 void Set(unsigned value);
283
284 // The successors are a list of sets that contain the same values
285 // as this set and the one more value that is not present in this
286 // set.
287 ZoneList<OutSet*>* successors() { return successors_; }
288
281 OutSet(uint32_t first, ZoneList<unsigned>* remaining) 289 OutSet(uint32_t first, ZoneList<unsigned>* remaining)
282 : first_(first), remaining_(remaining) { } 290 : first_(first), remaining_(remaining) { }
283 uint32_t first_; 291 uint32_t first_;
284 ZoneList<unsigned>* remaining_; 292 ZoneList<unsigned>* remaining_;
293 ZoneList<OutSet*>* successors_;
285 }; 294 };
286 295
287 296
288 // A mapping from integers, specified as ranges, to a set of integers. 297 // A mapping from integers, specified as ranges, to a set of integers.
289 // Used for mapping character ranges to choices. 298 // Used for mapping character ranges to choices.
290 class DispatchTable { 299 class DispatchTable {
291 public: 300 public:
292 class Entry { 301 class Entry {
293 public: 302 public:
294 Entry() 303 Entry()
295 : from_(0), to_(0) { } 304 : from_(0), to_(0) { }
296 Entry(uc16 from, uc16 to, OutSet out_set) 305 Entry(uc16 from, uc16 to, OutSet* out_set)
297 : from_(from), to_(to), out_set_(out_set) { } 306 : from_(from), to_(to), out_set_(out_set) { }
298 inline Entry(uc16 from, uc16 to, unsigned value);
299 uc16 from() { return from_; } 307 uc16 from() { return from_; }
300 uc16 to() { return to_; } 308 uc16 to() { return to_; }
301 void set_to(uc16 value) { to_ = value; } 309 void set_to(uc16 value) { to_ = value; }
302 void AddValue(int value) { out_set_.Set(value); } 310 void AddValue(int value) { out_set_ = out_set_->Extend(value); }
303 OutSet out_set() { return out_set_; } 311 OutSet* out_set() { return out_set_; }
304 private: 312 private:
305 uc16 from_; 313 uc16 from_;
306 uc16 to_; 314 uc16 to_;
307 OutSet out_set_; 315 OutSet* out_set_;
308 }; 316 };
317
309 class Config { 318 class Config {
310 public: 319 public:
311 typedef uc16 Key; 320 typedef uc16 Key;
312 typedef Entry Value; 321 typedef Entry Value;
313 static const uc16 kNoKey; 322 static const uc16 kNoKey;
314 static const Entry kNoValue; 323 static const Entry kNoValue;
315 static inline int Compare(uc16 a, uc16 b) { 324 static inline int Compare(uc16 a, uc16 b) {
316 if (a == b) 325 if (a == b)
317 return 0; 326 return 0;
318 else if (a < b) 327 else if (a < b)
319 return -1; 328 return -1;
320 else 329 else
321 return 1; 330 return 1;
322 } 331 }
323 }; 332 };
333
324 void AddRange(CharacterRange range, int value); 334 void AddRange(CharacterRange range, int value);
325 OutSet Get(uc16 value); 335 OutSet* Get(uc16 value);
326 void Dump(); 336 void Dump();
327 337
328 template <typename Callback> 338 template <typename Callback>
329 void ForEach(Callback callback) { return tree()->ForEach(callback); } 339 void ForEach(Callback callback) { return tree()->ForEach(callback); }
330 private: 340 private:
341 // There can't be a static empty set since it allocates its
342 // successors in a zone and caches them.
343 OutSet* empty() { return &empty_; }
344 OutSet empty_;
331 ZoneSplayTree<Config>* tree() { return &tree_; } 345 ZoneSplayTree<Config>* tree() { return &tree_; }
332 ZoneSplayTree<Config> tree_; 346 ZoneSplayTree<Config> tree_;
333 }; 347 };
334 348
335 349
336 struct RegExpParseResult { 350 struct RegExpParseResult {
337 RegExpTree* tree; 351 RegExpTree* tree;
338 bool has_character_escapes; 352 bool has_character_escapes;
339 Handle<String> error; 353 Handle<String> error;
340 int capture_count; 354 int capture_count;
341 }; 355 };
342 356
343 357
344 class RegExpEngine: public AllStatic { 358 class RegExpEngine: public AllStatic {
345 public: 359 public:
346 static RegExpNode* Compile(RegExpParseResult* input); 360 static RegExpNode* Compile(RegExpParseResult* input);
347 static void DotPrint(const char* label, RegExpNode* node); 361 static void DotPrint(const char* label, RegExpNode* node);
348 }; 362 };
349 363
350 364
351 } } // namespace v8::internal 365 } } // namespace v8::internal
352 366
353 #endif // V8_JSREGEXP_H_ 367 #endif // V8_JSREGEXP_H_
OLDNEW
« no previous file with comments | « no previous file | src/jsregexp.cc » ('j') | test/cctest/test-regexp.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698