OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 104 |
105 | 105 |
106 // Write the C code | 106 // Write the C code |
107 // const char* <varname> = "<str>"; | 107 // const char* <varname> = "<str>"; |
108 // const int <varname>_len = <len>; | 108 // const int <varname>_len = <len>; |
109 // to the file given by filename. Only the first len chars are written. | 109 // to the file given by filename. Only the first len chars are written. |
110 int WriteAsCFile(const char* filename, const char* varname, | 110 int WriteAsCFile(const char* filename, const char* varname, |
111 const char* str, int size, bool verbose = true); | 111 const char* str, int size, bool verbose = true); |
112 | 112 |
113 | 113 |
| 114 // ---------------------------------------------------------------------------- |
114 // Data structures | 115 // Data structures |
115 | 116 |
116 template <typename T> | 117 template <typename T> |
117 inline Vector< Handle<Object> > HandleVector(v8::internal::Handle<T>* elms, | 118 inline Vector< Handle<Object> > HandleVector(v8::internal::Handle<T>* elms, |
118 int length) { | 119 int length) { |
119 return Vector< Handle<Object> >( | 120 return Vector< Handle<Object> >( |
120 reinterpret_cast<v8::internal::Handle<Object>*>(elms), length); | 121 reinterpret_cast<v8::internal::Handle<Object>*>(elms), length); |
121 } | 122 } |
122 | 123 |
| 124 |
| 125 // ---------------------------------------------------------------------------- |
123 // Memory | 126 // Memory |
124 | 127 |
125 // Copies data from |src| to |dst|. The data spans must not overlap. | 128 // Copies data from |src| to |dst|. The data spans must not overlap. |
126 template <typename T> | 129 template <typename T> |
127 inline void CopyWords(T* dst, T* src, int num_words) { | 130 inline void CopyWords(T* dst, T* src, int num_words) { |
128 STATIC_ASSERT(sizeof(T) == kPointerSize); | 131 STATIC_ASSERT(sizeof(T) == kPointerSize); |
129 ASSERT(Min(dst, src) + num_words <= Max(dst, src)); | 132 ASSERT(Min(dst, src) + num_words <= Max(dst, src)); |
130 ASSERT(num_words > 0); | 133 ASSERT(num_words > 0); |
131 | 134 |
132 // Use block copying memcpy if the segment we're copying is | 135 // Use block copying OS::MemCopy if the segment we're copying is |
133 // enough to justify the extra call/setup overhead. | 136 // enough to justify the extra call/setup overhead. |
134 static const int kBlockCopyLimit = 16; | 137 static const int kBlockCopyLimit = 16; |
| 138 STATIC_ASSERT(kBlockCopyLimit * kPointerSize >= OS::kMinComplexMemCopy); |
135 | 139 |
136 if (num_words >= kBlockCopyLimit) { | 140 if (num_words >= kBlockCopyLimit) { |
137 memcpy(dst, src, num_words * kPointerSize); | 141 OS::MemCopy(dst, src, num_words * kPointerSize); |
138 } else { | 142 } else { |
139 int remaining = num_words; | 143 int remaining = num_words; |
140 do { | 144 do { |
141 remaining--; | 145 remaining--; |
142 *dst++ = *src++; | 146 *dst++ = *src++; |
143 } while (remaining > 0); | 147 } while (remaining > 0); |
144 } | 148 } |
145 } | 149 } |
146 | 150 |
147 | 151 |
148 // Copies data from |src| to |dst|. The data spans must not overlap. | 152 // Copies data from |src| to |dst|. The data spans must not overlap. |
149 template <typename T> | 153 template <typename T> |
150 inline void CopyBytes(T* dst, T* src, int num_bytes) { | 154 inline void CopyBytes(T* dst, T* src, int num_bytes) { |
151 STATIC_ASSERT(sizeof(T) == 1); | 155 STATIC_ASSERT(sizeof(T) == 1); |
152 ASSERT(Min(dst, src) + num_bytes <= Max(dst, src)); | 156 ASSERT(Min(dst, src) + num_bytes <= Max(dst, src)); |
153 ASSERT(num_bytes >= 0); | 157 ASSERT(num_bytes >= 0); |
154 if (num_bytes == 0) return; | 158 if (num_bytes == 0) return; |
155 | 159 |
156 // Use block copying memcpy if the segment we're copying is | 160 // Use block copying OS::MemCopy if the segment we're copying is |
157 // enough to justify the extra call/setup overhead. | 161 // enough to justify the extra call/setup overhead. |
158 static const int kBlockCopyLimit = OS::kMinComplexMemCopy; | 162 static const int kBlockCopyLimit = OS::kMinComplexMemCopy; |
159 | 163 |
160 if (num_bytes >= kBlockCopyLimit) { | 164 if (num_bytes >= kBlockCopyLimit) { |
161 OS::MemCopy(dst, src, num_bytes); | 165 OS::MemCopy(dst, src, num_bytes); |
162 } else { | 166 } else { |
163 int remaining = num_bytes; | 167 int remaining = num_bytes; |
164 do { | 168 do { |
165 remaining--; | 169 remaining--; |
166 *dst++ = *src++; | 170 *dst++ = *src++; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 302 |
299 // Add formatted contents like printf based on a va_list. | 303 // Add formatted contents like printf based on a va_list. |
300 void AddFormattedList(const char* format, va_list list); | 304 void AddFormattedList(const char* format, va_list list); |
301 private: | 305 private: |
302 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); | 306 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); |
303 }; | 307 }; |
304 | 308 |
305 } } // namespace v8::internal | 309 } } // namespace v8::internal |
306 | 310 |
307 #endif // V8_V8UTILS_H_ | 311 #endif // V8_V8UTILS_H_ |
OLD | NEW |