Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: src/utils.cc

Issue 306473004: Reland 21502 - "Move OS::MemCopy and OS::MemMove out of platform to utils" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « src/utils.h ('k') | src/v8.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdarg.h> 5 #include <stdarg.h>
6 #include <sys/stat.h> 6 #include <sys/stat.h>
7 7
8 #include "v8.h" 8 #include "v8.h"
9 9
10 #include "checks.h" 10 #include "checks.h"
(...skipping 11 matching lines...) Expand all
22 22
23 23
24 void SimpleStringBuilder::AddString(const char* s) { 24 void SimpleStringBuilder::AddString(const char* s) {
25 AddSubstring(s, StrLength(s)); 25 AddSubstring(s, StrLength(s));
26 } 26 }
27 27
28 28
29 void SimpleStringBuilder::AddSubstring(const char* s, int n) { 29 void SimpleStringBuilder::AddSubstring(const char* s, int n) {
30 ASSERT(!is_finalized() && position_ + n <= buffer_.length()); 30 ASSERT(!is_finalized() && position_ + n <= buffer_.length());
31 ASSERT(static_cast<size_t>(n) <= strlen(s)); 31 ASSERT(static_cast<size_t>(n) <= strlen(s));
32 OS::MemCopy(&buffer_[position_], s, n * kCharSize); 32 MemCopy(&buffer_[position_], s, n * kCharSize);
33 position_ += n; 33 position_ += n;
34 } 34 }
35 35
36 36
37 void SimpleStringBuilder::AddPadding(char c, int count) { 37 void SimpleStringBuilder::AddPadding(char c, int count) {
38 for (int i = 0; i < count; i++) { 38 for (int i = 0; i < count; i++) {
39 AddCharacter(c); 39 AddCharacter(c);
40 } 40 }
41 } 41 }
42 42
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 138 }
139 if (result == NULL) { 139 if (result == NULL) {
140 // Allocate the initial result and make room for the terminating '\0' 140 // Allocate the initial result and make room for the terminating '\0'
141 result = NewArray<char>(len + 1); 141 result = NewArray<char>(len + 1);
142 } else { 142 } else {
143 // Allocate a new result with enough room for the new addition. 143 // Allocate a new result with enough room for the new addition.
144 int new_len = offset + len + 1; 144 int new_len = offset + len + 1;
145 char* new_result = NewArray<char>(new_len); 145 char* new_result = NewArray<char>(new_len);
146 // Copy the existing input into the new array and set the new 146 // Copy the existing input into the new array and set the new
147 // array as the result. 147 // array as the result.
148 OS::MemCopy(new_result, result, offset * kCharSize); 148 MemCopy(new_result, result, offset * kCharSize);
149 DeleteArray(result); 149 DeleteArray(result);
150 result = new_result; 150 result = new_result;
151 } 151 }
152 // Copy the newly read line into the result. 152 // Copy the newly read line into the result.
153 OS::MemCopy(result + offset, line_buf, len * kCharSize); 153 MemCopy(result + offset, line_buf, len * kCharSize);
154 offset += len; 154 offset += len;
155 } 155 }
156 ASSERT(result != NULL); 156 ASSERT(result != NULL);
157 result[offset] = '\0'; 157 result[offset] = '\0';
158 return result; 158 return result;
159 } 159 }
160 160
161 161
162 char* ReadCharsFromFile(FILE* file, 162 char* ReadCharsFromFile(FILE* file,
163 int* size, 163 int* size,
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 ASSERT(!is_finalized() && position_ <= buffer_.length()); 307 ASSERT(!is_finalized() && position_ <= buffer_.length());
308 int n = OS::VSNPrintF(buffer_ + position_, format, list); 308 int n = OS::VSNPrintF(buffer_ + position_, format, list);
309 if (n < 0 || n >= (buffer_.length() - position_)) { 309 if (n < 0 || n >= (buffer_.length() - position_)) {
310 position_ = buffer_.length(); 310 position_ = buffer_.length();
311 } else { 311 } else {
312 position_ += n; 312 position_ += n;
313 } 313 }
314 } 314 }
315 315
316 316
317 #if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X87
318 static void MemMoveWrapper(void* dest, const void* src, size_t size) {
319 memmove(dest, src, size);
320 }
321
322
323 // Initialize to library version so we can call this at any time during startup.
324 static MemMoveFunction memmove_function = &MemMoveWrapper;
325
326 // Defined in codegen-ia32.cc.
327 MemMoveFunction CreateMemMoveFunction();
328
329 // Copy memory area to disjoint memory area.
330 void MemMove(void* dest, const void* src, size_t size) {
331 if (size == 0) return;
332 // Note: here we rely on dependent reads being ordered. This is true
333 // on all architectures we currently support.
334 (*memmove_function)(dest, src, size);
335 }
336
337 #elif V8_OS_POSIX && V8_HOST_ARCH_ARM
338 void MemCopyUint16Uint8Wrapper(uint16_t* dest, const uint8_t* src,
339 size_t chars) {
340 uint16_t* limit = dest + chars;
341 while (dest < limit) {
342 *dest++ = static_cast<uint16_t>(*src++);
343 }
344 }
345
346
347 MemCopyUint8Function memcopy_uint8_function = &MemCopyUint8Wrapper;
348 MemCopyUint16Uint8Function memcopy_uint16_uint8_function =
349 &MemCopyUint16Uint8Wrapper;
350 // Defined in codegen-arm.cc.
351 MemCopyUint8Function CreateMemCopyUint8Function(MemCopyUint8Function stub);
352 MemCopyUint16Uint8Function CreateMemCopyUint16Uint8Function(
353 MemCopyUint16Uint8Function stub);
354
355 #elif V8_OS_POSIX && V8_HOST_ARCH_MIPS
356 MemCopyUint8Function memcopy_uint8_function = &MemCopyUint8Wrapper;
357 // Defined in codegen-mips.cc.
358 MemCopyUint8Function CreateMemCopyUint8Function(MemCopyUint8Function stub);
359 #endif
360
361
362 void init_memcopy_functions() {
363 #if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X87
364 MemMoveFunction generated_memmove = CreateMemMoveFunction();
365 if (generated_memmove != NULL) {
366 memmove_function = generated_memmove;
367 }
368 #elif V8_OS_POSIX && V8_HOST_ARCH_ARM
369 memcopy_uint8_function = CreateMemCopyUint8Function(&MemCopyUint8Wrapper);
370 memcopy_uint16_uint8_function =
371 CreateMemCopyUint16Uint8Function(&MemCopyUint16Uint8Wrapper);
372 #elif V8_OS_POSIX && V8_HOST_ARCH_MIPS
373 memcopy_uint8_function = CreateMemCopyUint8Function(&MemCopyUint8Wrapper);
374 #endif
375 }
376
377
317 } } // namespace v8::internal 378 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/utils.h ('k') | src/v8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698