Chromium Code Reviews| Index: src/profile-generator.cc |
| =================================================================== |
| --- src/profile-generator.cc (revision 11222) |
| +++ src/profile-generator.cc (working copy) |
| @@ -3353,9 +3353,7 @@ |
| MaybeWriteChunk(); |
| } |
| } |
| - void AddNumber(int n) { AddNumberImpl<int>(n, "%d"); } |
| void AddNumber(unsigned n) { AddNumberImpl<unsigned>(n, "%u"); } |
| - void AddNumber(uint64_t n) { AddNumberImpl<uint64_t>(n, "%llu"); } |
| void Finalize() { |
| if (aborted_) return; |
| ASSERT(chunk_pos_ < chunk_size_); |
| @@ -3510,6 +3508,30 @@ |
| } |
| +static char* itoa(int value, char* buffer) { |
|
mnaganov (inactive)
2012/04/04 10:03:31
Have you tried IntToCString? It uses Vector, which
alexeif
2012/04/04 11:20:49
I have more concerns regarding the checks in relea
yurys
2012/04/04 12:32:16
IntToCString will place the number into the end of
|
| + if (value < 0) { |
| + *buffer = '-'; |
| + ++buffer; |
| + value = -value; |
| + } |
| + |
| + int number_of_digits = 0; |
| + int t = value; |
| + do { |
| + ++number_of_digits; |
| + } while (t /= 10); |
| + |
| + buffer += number_of_digits; |
| + char* result = buffer; |
| + do { |
| + int last_digit = value % 10; |
| + value /= 10; |
| + *--buffer = '0' + last_digit; |
| + } while (value); |
| + return result; |
| +} |
| + |
| + |
| void HeapSnapshotJSONSerializer::SerializeEdge(HeapGraphEdge* edge) { |
| // The buffer needs space for 3 ints, 3 commas and \0 |
| static const int kBufferSize = |
| @@ -3522,10 +3544,15 @@ |
| STATIC_CHECK(sizeof(int) == sizeof(edge->type())); // NOLINT |
| STATIC_CHECK(sizeof(int) == sizeof(edge_name_or_index)); // NOLINT |
| STATIC_CHECK(sizeof(int) == sizeof(GetNodeId(edge->to()))); // NOLINT |
| - int result = OS::SNPrintF(buffer, ",%d,%d,%d", |
| - edge->type(), edge_name_or_index, GetNodeId(edge->to())); |
| - USE(result); |
| - ASSERT(result != -1); |
| + char* buffer_pos = buffer.start(); |
| + *buffer_pos++ = ','; |
| + buffer_pos = itoa(edge->type(), buffer_pos); |
| + *buffer_pos++ = ','; |
| + buffer_pos = itoa(edge_name_or_index, buffer_pos); |
| + *buffer_pos++ = ','; |
| + buffer_pos = itoa(GetNodeId(edge->to()), buffer_pos); |
| + *buffer_pos++ = '\0'; |
| + ASSERT(buffer_pos <= (buffer.start() + buffer.length())); |
| writer_->AddString(buffer.start()); |
| } |
| @@ -3545,16 +3572,24 @@ |
| STATIC_CHECK(sizeof(int) == sizeof(entry->retained_size())); // NOLINT |
| STATIC_CHECK(sizeof(int) == sizeof(GetNodeId(entry->dominator()))); // NOLINT |
| STATIC_CHECK(sizeof(int) == sizeof(children.length())); // NOLINT |
| - int result = OS::SNPrintF(buffer, "\n,%d,%d,%u,%d,%d,%d,%d", |
| - entry->type(), |
| - GetStringId(entry->name()), |
| - entry->id(), |
| - entry->self_size(), |
| - entry->retained_size(), |
| - GetNodeId(entry->dominator()), |
| - children.length()); |
| - USE(result); |
| - ASSERT(result != -1); |
| + char* buffer_pos = buffer.start(); |
| + *buffer_pos++ = '\n'; |
| + *buffer_pos++ = ','; |
| + buffer_pos = itoa(entry->type(), buffer_pos); |
| + *buffer_pos++ = ','; |
| + buffer_pos = itoa(GetStringId(entry->name()), buffer_pos); |
| + *buffer_pos++ = ','; |
| + buffer_pos = itoa(entry->id(), buffer_pos); |
| + *buffer_pos++ = ','; |
| + buffer_pos = itoa(entry->self_size(), buffer_pos); |
| + *buffer_pos++ = ','; |
| + buffer_pos = itoa(entry->retained_size(), buffer_pos); |
| + *buffer_pos++ = ','; |
| + buffer_pos = itoa(GetNodeId(entry->dominator()), buffer_pos); |
| + *buffer_pos++ = ','; |
| + buffer_pos = itoa(children.length(), buffer_pos); |
| + *buffer_pos++ = '\0'; |
| + ASSERT(buffer_pos <= (buffer.start() + buffer.length())); |
| writer_->AddString(buffer.start()); |
| for (int i = 0; i < children.length(); ++i) { |
| SerializeEdge(&children[i]); |