Chromium Code Reviews| Index: base/tracked.cc |
| diff --git a/base/tracked.cc b/base/tracked.cc |
| index 124e721c727e8408c46b9025432f0e287b399c2b..904adc45a6cee1f7c8b7509ad12249d45085530d 100644 |
| --- a/base/tracked.cc |
| +++ b/base/tracked.cc |
| @@ -13,6 +13,7 @@ void* _ReturnAddress(); |
| #include "base/tracked.h" |
| +#include "base/string_number_conversions.h" |
| #include "base/stringprintf.h" |
| #include "base/tracked_objects.h" |
| @@ -22,28 +23,42 @@ namespace tracked_objects { |
| //------------------------------------------------------------------------------ |
| -Location::Location(const char* function_name, |
| - const char* file_name, |
| - int line_number, |
| +Location::Location(const char* file_line, |
| + const char* function_name, |
| const void* program_counter) |
| - : function_name_(function_name), |
| - file_name_(file_name), |
| - line_number_(line_number), |
| + : file_line_(file_line), |
| + function_name_(function_name), |
| program_counter_(program_counter) { |
| } |
| Location::Location() |
| - : function_name_("Unknown"), |
| - file_name_("Unknown"), |
| - line_number_(-1), |
| + : file_line_("Unknown:-1"), |
| + function_name_("Unknown"), |
| program_counter_(NULL) { |
| } |
| +const base::StringPiece Location::file_name() const { |
| + base::StringPiece file_line(file_line_); |
| + return file_line.substr(0, file_line.find_last_of(':')); |
| +} |
| + |
| +int Location::line_number() const { |
| + base::StringPiece file_line(file_line_); |
| + base::StringPiece::size_type colon1 = file_line.find_last_of(':'); |
| + int line_num = 0; |
| + base::StringToInt(file_line.substr(colon1).as_string(), &line_num); |
| + return line_num; |
| +} |
| + |
| +const base::StringPiece Location::function_name() const { |
| + return base::StringPiece(function_name_); |
|
joth
2011/09/15 10:38:09
nit: is there any point returning this as a string
jbates
2011/09/15 16:48:33
I went back and forth on this one -- I was on the
|
| +} |
| + |
| void Location::Write(bool display_filename, bool display_function_name, |
| std::string* output) const { |
| base::StringAppendF(output, "%s[%d] ", |
| - display_filename ? file_name_ : "line", |
| - line_number_); |
| + display_filename ? file_name().as_string().c_str() : "line", |
| + line_number()); |
| if (display_function_name) { |
| WriteFunctionName(output); |
| @@ -96,7 +111,7 @@ void Tracked::SetBirthPlace(const Location& from_here) { |
| } |
| const Location Tracked::GetBirthPlace() const { |
| - static Location kNone("NoFunctionName", "NeedToSetBirthPlace", -1, NULL); |
| + static Location kNone("NeedToSetBirthPlace:-1", "NoFunctionName", NULL); |
| return kNone; |
| } |
| bool Tracked::MissingBirthPlace() const { return false; } |
| @@ -130,7 +145,7 @@ void Tracked::SetBirthPlace(const Location& from_here) { |
| } |
| const Location Tracked::GetBirthPlace() const { |
| - static Location kNone("UnknownFunctionName", "UnknownFile", -1, NULL); |
| + static Location kNone; |
| return tracked_births_ ? tracked_births_->location() : kNone; |
| } |
| @@ -139,7 +154,8 @@ void Tracked::ResetBirthTime() { |
| } |
| bool Tracked::MissingBirthPlace() const { |
| - return !tracked_births_ || tracked_births_->location().line_number() == -1; |
| + return !tracked_births_ || |
| + tracked_births_->location().program_counter() == NULL; |
| } |
| #endif // !defined(TRACK_ALL_TASK_OBJECTS) |