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/list-inl.h

Issue 9104: Dispatch tables (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
« src/jsregexp.cc ('K') | « src/list.h ('k') | src/parser.cc » ('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 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 83 }
84 84
85 85
86 template<typename T, class P> 86 template<typename T, class P>
87 void List<T, P>::Iterate(void (*callback)(T* x)) { 87 void List<T, P>::Iterate(void (*callback)(T* x)) {
88 for (int i = 0; i < length_; i++) callback(&data_[i]); 88 for (int i = 0; i < length_; i++) callback(&data_[i]);
89 } 89 }
90 90
91 91
92 template<typename T, class P> 92 template<typename T, class P>
93 bool List<T, P>::Contains(T& elm) {
94 for (int i = 0; i < length_; i++) {
95 if (data_[i] == elm)
96 return true;
97 }
98 return false;
99 }
100
101
102 template<typename T, class P>
93 void List<T, P>::Sort(int (*cmp)(const T* x, const T* y)) { 103 void List<T, P>::Sort(int (*cmp)(const T* x, const T* y)) {
94 qsort(data_, 104 qsort(data_,
95 length_, 105 length_,
96 sizeof(T), 106 sizeof(T),
97 reinterpret_cast<int (*)(const void*, const void*)>(cmp)); 107 reinterpret_cast<int (*)(const void*, const void*)>(cmp));
98 #ifdef DEBUG 108 #ifdef DEBUG
99 for (int i = 1; i < length_; i++) 109 for (int i = 1; i < length_; i++)
100 ASSERT(cmp(&data_[i - 1], &data_[i]) <= 0); 110 ASSERT(cmp(&data_[i - 1], &data_[i]) <= 0);
101 #endif 111 #endif
102 } 112 }
103 113
104 114
105 template<typename T, class P> 115 template<typename T, class P>
106 void List<T, P>::Initialize(int capacity) { 116 void List<T, P>::Initialize(int capacity) {
107 ASSERT(capacity >= 0); 117 ASSERT(capacity >= 0);
108 data_ = (capacity > 0) ? NewData(capacity) : NULL; 118 data_ = (capacity > 0) ? NewData(capacity) : NULL;
109 capacity_ = capacity; 119 capacity_ = capacity;
110 length_ = 0; 120 length_ = 0;
111 } 121 }
112 122
113 123
114 } } // namespace v8::internal 124 } } // namespace v8::internal
115 125
116 #endif // V8_LIST_INL_H_ 126 #endif // V8_LIST_INL_H_
OLDNEW
« src/jsregexp.cc ('K') | « src/list.h ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698