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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 // The returned buffer must be freed by the caller. | 195 // The returned buffer must be freed by the caller. |
196 // On return, *exits tells whether the file existed. | 196 // On return, *exits tells whether the file existed. |
197 Vector<const char> ReadFile(const char* filename, | 197 Vector<const char> ReadFile(const char* filename, |
198 bool* exists, | 198 bool* exists, |
199 bool verbose = true); | 199 bool verbose = true); |
200 Vector<const char> ReadFile(FILE* file, | 200 Vector<const char> ReadFile(FILE* file, |
201 bool* exists, | 201 bool* exists, |
202 bool verbose = true); | 202 bool verbose = true); |
203 | 203 |
204 | 204 |
| 205 template <typename sourcechar, typename sinkchar> |
| 206 INLINE(static void CopyCharsUnsigned(sinkchar* dest, |
| 207 const sourcechar* src, |
| 208 int chars)); |
| 209 |
205 // Copy from ASCII/16bit chars to ASCII/16bit chars. | 210 // Copy from ASCII/16bit chars to ASCII/16bit chars. |
206 template <typename sourcechar, typename sinkchar> | 211 template <typename sourcechar, typename sinkchar> |
207 INLINE(void CopyChars(sinkchar* dest, const sourcechar* src, int chars)); | 212 INLINE(void CopyChars(sinkchar* dest, const sourcechar* src, int chars)); |
208 | 213 |
| 214 template<typename sourcechar, typename sinkchar> |
| 215 void CopyChars(sinkchar* dest, const sourcechar* src, int chars) { |
| 216 ASSERT(sizeof(sourcechar) <= 2); |
| 217 ASSERT(sizeof(sinkchar) <= 2); |
| 218 if (sizeof(sinkchar) == 1) { |
| 219 if (sizeof(sourcechar) == 1) { |
| 220 CopyCharsUnsigned(reinterpret_cast<uint8_t*>(dest), |
| 221 reinterpret_cast<const uint8_t*>(src), |
| 222 chars); |
| 223 } else { |
| 224 CopyCharsUnsigned(reinterpret_cast<uint8_t*>(dest), |
| 225 reinterpret_cast<const uint16_t*>(src), |
| 226 chars); |
| 227 } |
| 228 } else { |
| 229 if (sizeof(sourcechar) == 1) { |
| 230 CopyCharsUnsigned(reinterpret_cast<uint16_t*>(dest), |
| 231 reinterpret_cast<const uint8_t*>(src), |
| 232 chars); |
| 233 } else { |
| 234 CopyCharsUnsigned(reinterpret_cast<uint16_t*>(dest), |
| 235 reinterpret_cast<const uint16_t*>(src), |
| 236 chars); |
| 237 } |
| 238 } |
| 239 } |
209 | 240 |
210 template <typename sourcechar, typename sinkchar> | 241 template <typename sourcechar, typename sinkchar> |
211 void CopyChars(sinkchar* dest, const sourcechar* src, int chars) { | 242 void CopyCharsUnsigned(sinkchar* dest, const sourcechar* src, int chars) { |
212 sinkchar* limit = dest + chars; | 243 sinkchar* limit = dest + chars; |
213 #ifdef V8_HOST_CAN_READ_UNALIGNED | 244 #ifdef V8_HOST_CAN_READ_UNALIGNED |
214 if (sizeof(*dest) == sizeof(*src)) { | 245 if (sizeof(*dest) == sizeof(*src)) { |
215 if (chars >= static_cast<int>(OS::kMinComplexMemCopy / sizeof(*dest))) { | 246 if (chars >= static_cast<int>(OS::kMinComplexMemCopy / sizeof(*dest))) { |
216 OS::MemCopy(dest, src, chars * sizeof(*dest)); | 247 OS::MemCopy(dest, src, chars * sizeof(*dest)); |
217 return; | 248 return; |
218 } | 249 } |
219 // Number of characters in a uintptr_t. | 250 // Number of characters in a uintptr_t. |
220 static const int kStepSize = sizeof(uintptr_t) / sizeof(*dest); // NOLINT | 251 static const int kStepSize = sizeof(uintptr_t) / sizeof(*dest); // NOLINT |
221 while (dest <= limit - kStepSize) { | 252 while (dest <= limit - kStepSize) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 304 |
274 // Add formatted contents like printf based on a va_list. | 305 // Add formatted contents like printf based on a va_list. |
275 void AddFormattedList(const char* format, va_list list); | 306 void AddFormattedList(const char* format, va_list list); |
276 private: | 307 private: |
277 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); | 308 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); |
278 }; | 309 }; |
279 | 310 |
280 } } // namespace v8::internal | 311 } } // namespace v8::internal |
281 | 312 |
282 #endif // V8_V8UTILS_H_ | 313 #endif // V8_V8UTILS_H_ |
OLD | NEW |