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

Unified Diff: runtime/vm/os_linux.cc

Issue 1331623002: Uses SNPRINT macro where possible. Otherwise uses #define for format. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/os_linux.cc
diff --git a/runtime/vm/os_linux.cc b/runtime/vm/os_linux.cc
index 288db46c139081729e30ea1eb31858fd6928121c..16cddbba6f144002ac3e45510955a873fe0b5278 100644
--- a/runtime/vm/os_linux.cc
+++ b/runtime/vm/os_linux.cc
@@ -49,13 +49,11 @@ class PerfCodeObserver : public CodeObserver {
if (file_open == NULL) {
return;
}
- const char* format = "/tmp/perf-%" Pd ".map";
intptr_t pid = getpid();
- intptr_t len = OS::SNPrint(NULL, 0, format, pid);
- char* filename = new char[len + 1];
- OS::SNPrint(filename, len + 1, format, pid);
+ char* filename = NULL;
+ SNPRINT(filename, malloc, "/tmp/perf-%" Pd ".map", pid);
out_file_ = (*file_open)(filename, true);
- delete[] filename;
+ free(filename);
}
~PerfCodeObserver() {
@@ -79,14 +77,13 @@ class PerfCodeObserver : public CodeObserver {
if ((file_write == NULL) || (out_file_ == NULL)) {
return;
}
- const char* format = "%" Px " %" Px " %s%s\n";
const char* marker = optimized ? "*" : "";
- intptr_t len = OS::SNPrint(NULL, 0, format, base, size, marker, name);
- char* buffer = Thread::Current()->zone()->Alloc<char>(len + 1);
- OS::SNPrint(buffer, len + 1, format, base, size, marker, name);
+ char* buffer = NULL;
+ SNPRINT(buffer, Thread::Current()->zone()->Alloc<char>,
+ "%" Px " %" Px " %s%s\n", base, size, marker, name);
{
MutexLocker ml(CodeObservers::mutex());
- (*file_write)(buffer, len, out_file_);
+ (*file_write)(buffer, strlen(buffer), out_file_);
}
}
@@ -116,10 +113,9 @@ class GdbCodeObserver : public CodeObserver {
// the prologue sequence is not the first instruction:
// <name>_entry is used for code preceding the prologue sequence.
// <name> for rest of the code (first instruction is prologue sequence).
- const char* kFormat = "%s_%s";
- intptr_t len = OS::SNPrint(NULL, 0, kFormat, name, "entry");
- char* pname = Thread::Current()->zone()->Alloc<char>(len + 1);
- OS::SNPrint(pname, (len + 1), kFormat, name, "entry");
+ char* pname = NULL;
+ SNPRINT(pname, Thread::Current()->zone()->Alloc<char>, "%s_%s",
+ name, "entry");
DebugInfo::RegisterSection(pname, base, size);
DebugInfo::RegisterSection(name,
(base + prologue_offset),
@@ -245,11 +241,10 @@ class JitdumpCodeObserver : public CodeObserver {
};
const char* GenerateCodeName(const char* name, bool optimized) {
- const char* format = "%s%s";
const char* marker = optimized ? "*" : "";
- intptr_t len = OS::SNPrint(NULL, 0, format, marker, name);
- char* buffer = Thread::Current()->zone()->Alloc<char>(len + 1);
- OS::SNPrint(buffer, len + 1, format, marker, name);
+ char* buffer = NULL;
+ SNPRINT(buffer, Thread::Current()->zone()->Alloc<char>, "%s%s",
+ marker, name);
return buffer;
}
« runtime/vm/assembler.cc ('K') | « runtime/vm/os_android.cc ('k') | runtime/vm/snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698