OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 void StringBuilder::AddFormattedList(const char* format, va_list list) { | 266 void StringBuilder::AddFormattedList(const char* format, va_list list) { |
267 ASSERT(!is_finalized() && position_ < buffer_.length()); | 267 ASSERT(!is_finalized() && position_ < buffer_.length()); |
268 int n = OS::VSNPrintF(buffer_ + position_, format, list); | 268 int n = OS::VSNPrintF(buffer_ + position_, format, list); |
269 if (n < 0 || n >= (buffer_.length() - position_)) { | 269 if (n < 0 || n >= (buffer_.length() - position_)) { |
270 position_ = buffer_.length(); | 270 position_ = buffer_.length(); |
271 } else { | 271 } else { |
272 position_ += n; | 272 position_ += n; |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 | |
277 MemoryMappedExternalResource::MemoryMappedExternalResource(const char* filename) | |
278 : filename_(NULL), | |
279 data_(NULL), | |
280 length_(0), | |
281 remove_file_on_cleanup_(false) { | |
282 Init(filename); | |
283 } | |
284 | |
285 | |
286 MemoryMappedExternalResource:: | |
287 MemoryMappedExternalResource(const char* filename, | |
288 bool remove_file_on_cleanup) | |
289 : filename_(NULL), | |
290 data_(NULL), | |
291 length_(0), | |
292 remove_file_on_cleanup_(remove_file_on_cleanup) { | |
293 Init(filename); | |
294 } | |
295 | |
296 | |
297 MemoryMappedExternalResource::~MemoryMappedExternalResource() { | |
298 // Release the resources if we had successfully acquired them: | |
299 if (file_ != NULL) { | |
300 delete file_; | |
301 if (remove_file_on_cleanup_) { | |
302 OS::Remove(filename_); | |
303 } | |
304 DeleteArray<char>(filename_); | |
305 } | |
306 } | |
307 | |
308 | |
309 void MemoryMappedExternalResource::Init(const char* filename) { | |
310 file_ = OS::MemoryMappedFile::open(filename); | |
311 if (file_ != NULL) { | |
312 filename_ = StrDup(filename); | |
313 data_ = reinterpret_cast<char*>(file_->memory()); | |
314 length_ = file_->size(); | |
315 } | |
316 } | |
317 | |
318 } } // namespace v8::internal | 276 } } // namespace v8::internal |
OLD | NEW |