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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 src += kStepSize; | 257 src += kStepSize; |
258 } | 258 } |
259 } | 259 } |
260 #endif | 260 #endif |
261 while (dest < limit) { | 261 while (dest < limit) { |
262 *dest++ = static_cast<sinkchar>(*src++); | 262 *dest++ = static_cast<sinkchar>(*src++); |
263 } | 263 } |
264 } | 264 } |
265 | 265 |
266 | 266 |
267 // A resource for using mmapped files to back external strings that are read | |
268 // from files. | |
269 class MemoryMappedExternalResource: public | |
270 v8::String::ExternalAsciiStringResource { | |
271 public: | |
272 explicit MemoryMappedExternalResource(const char* filename); | |
273 MemoryMappedExternalResource(const char* filename, | |
274 bool remove_file_on_cleanup); | |
275 virtual ~MemoryMappedExternalResource(); | |
276 | |
277 virtual const char* data() const { return data_; } | |
278 virtual size_t length() const { return length_; } | |
279 | |
280 bool exists() const { return file_ != NULL; } | |
281 bool is_empty() const { return length_ == 0; } | |
282 | |
283 private: | |
284 void Init(const char* filename); | |
285 | |
286 char* filename_; | |
287 OS::MemoryMappedFile* file_; | |
288 | |
289 const char* data_; | |
290 size_t length_; | |
291 bool remove_file_on_cleanup_; | |
292 }; | |
293 | |
294 class StringBuilder : public SimpleStringBuilder { | 267 class StringBuilder : public SimpleStringBuilder { |
295 public: | 268 public: |
296 explicit StringBuilder(int size) : SimpleStringBuilder(size) { } | 269 explicit StringBuilder(int size) : SimpleStringBuilder(size) { } |
297 StringBuilder(char* buffer, int size) : SimpleStringBuilder(buffer, size) { } | 270 StringBuilder(char* buffer, int size) : SimpleStringBuilder(buffer, size) { } |
298 | 271 |
299 // Add formatted contents to the builder just like printf(). | 272 // Add formatted contents to the builder just like printf(). |
300 void AddFormatted(const char* format, ...); | 273 void AddFormatted(const char* format, ...); |
301 | 274 |
302 // Add formatted contents like printf based on a va_list. | 275 // Add formatted contents like printf based on a va_list. |
303 void AddFormattedList(const char* format, va_list list); | 276 void AddFormattedList(const char* format, va_list list); |
304 private: | 277 private: |
305 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); | 278 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); |
306 }; | 279 }; |
307 | 280 |
308 } } // namespace v8::internal | 281 } } // namespace v8::internal |
309 | 282 |
310 #endif // V8_V8UTILS_H_ | 283 #endif // V8_V8UTILS_H_ |
OLD | NEW |