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

Side by Side Diff: runtime/platform/json.cc

Issue 10383122: Eliminate need for va_copy in json.cc (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | « runtime/platform/json.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/json.h" 5 #include "platform/json.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "platform/globals.h" 8 #include "platform/globals.h"
9 #include "platform/utils.h" 9 #include "platform/utils.h"
10 #include "vm/os.h" 10 #include "vm/os.h"
11 11
12 namespace dart { 12 namespace dart {
13 13
14 #ifndef va_copy
15 #define va_copy(dst, src) (memmove(&(dst), &(src), sizeof(dst)))
16 #endif /* va_copy */
17
18
19 JSONScanner::JSONScanner(const char* json_text) { 14 JSONScanner::JSONScanner(const char* json_text) {
20 SetText(json_text); 15 SetText(json_text);
21 } 16 }
22 17
23 18
24 void JSONScanner::SetText(const char* json_text) { 19 void JSONScanner::SetText(const char* json_text) {
25 current_pos_ = json_text; 20 current_pos_ = json_text;
26 token_start_ = json_text; 21 token_start_ = json_text;
27 token_length_ = 0; 22 token_length_ = 0;
28 token_ = TokenIllegal; 23 token_ = TokenIllegal;
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 buf_ = NULL; 342 buf_ = NULL;
348 } 343 }
349 344
350 345
351 void TextBuffer::Clear() { 346 void TextBuffer::Clear() {
352 msg_len_ = 0; 347 msg_len_ = 0;
353 buf_[0] = '\0'; 348 buf_[0] = '\0';
354 } 349 }
355 350
356 351
357 intptr_t TextBuffer::Printf(const char* format, va_list args) { 352 intptr_t TextBuffer::Printf(const char* format, ...) {
358 va_list args1; 353 va_list args;
359 va_copy(args1, args); 354 va_start(args, format);
360 intptr_t remaining = buf_size_ - msg_len_; 355 intptr_t remaining = buf_size_ - msg_len_;
361 ASSERT(remaining >= 0); 356 ASSERT(remaining >= 0);
362 intptr_t len = OS::VSNPrint(buf_ + msg_len_, remaining, format, args1); 357 intptr_t len = OS::VSNPrint(buf_ + msg_len_, remaining, format, args);
363 va_end(args1); 358 va_end(args);
364 if (len >= remaining) { 359 if (len >= remaining) {
365 const int kBufferSpareCapacity = 64; // Somewhat arbitrary. 360 const int kBufferSpareCapacity = 64; // Somewhat arbitrary.
366 GrowBuffer(len + kBufferSpareCapacity); 361 GrowBuffer(len + kBufferSpareCapacity);
367 remaining = buf_size_ - msg_len_; 362 remaining = buf_size_ - msg_len_;
368 ASSERT(remaining > len); 363 ASSERT(remaining > len);
369 va_list args2; 364 va_list args2;
370 va_copy(args2, args); 365 va_start(args2, format);
371 intptr_t len2 = OS::VSNPrint(buf_ + msg_len_, remaining, format, args2); 366 intptr_t len2 = OS::VSNPrint(buf_ + msg_len_, remaining, format, args2);
372 va_end(args2); 367 va_end(args2);
373 ASSERT(len == len2); 368 ASSERT(len == len2);
374 } 369 }
375 msg_len_ += len; 370 msg_len_ += len;
376 buf_[msg_len_] = '\0'; 371 buf_[msg_len_] = '\0';
377 return len; 372 return len;
378 } 373 }
379 374
380 375
381 intptr_t TextBuffer::Printf(const char* format, ...) {
382 va_list args;
383 va_start(args, format);
384 intptr_t len = this->Printf(format, args);
385 va_end(args);
386 return len;
387 }
388
389
390 void TextBuffer::GrowBuffer(intptr_t len) { 376 void TextBuffer::GrowBuffer(intptr_t len) {
391 intptr_t new_size = buf_size_ + len; 377 intptr_t new_size = buf_size_ + len;
392 char* new_buf = reinterpret_cast<char*>(realloc(buf_, new_size)); 378 char* new_buf = reinterpret_cast<char*>(realloc(buf_, new_size));
393 ASSERT(new_buf != NULL); 379 ASSERT(new_buf != NULL);
394 buf_ = new_buf; 380 buf_ = new_buf;
395 buf_size_ = new_size; 381 buf_size_ = new_size;
396 } 382 }
397 383
398 } // namespace dart 384 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/platform/json.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698