Make StringPiece data members private.
authorThiago Farina <tfarina@chromium.org>
Sat, 30 Jun 2012 14:40:10 +0000 (11:40 -0300)
committerThiago Farina <tfarina@chromium.org>
Sat, 30 Jun 2012 14:40:10 +0000 (11:40 -0300)
Signed-off-by: Thiago Farina <tfarina@chromium.org>
src/build_log.cc
src/depfile_parser.cc
src/edit_distance.cc
src/eval_env.cc
src/graph.cc
src/hash_map.h
src/lexer.cc
src/string_piece.h

index 02a9fb599a8c924c1d49c4c7f9fda83276dac5ea..0a44817392ec2e0b748205db9817bafb4595f350 100644 (file)
@@ -80,7 +80,7 @@ uint64_t MurmurHash64A(const void* key, int len) {
   h *= m;
   h ^= h >> r;
   return h;
-} 
+}
 #undef BIG_CONSTANT
 
 
@@ -88,7 +88,7 @@ uint64_t MurmurHash64A(const void* key, int len) {
 
 // static
 uint64_t BuildLog::LogEntry::HashCommand(StringPiece command) {
-  return MurmurHash64A(command.str_, command.len_);
+  return MurmurHash64A(command.str(), command.len());
 }
 
 BuildLog::BuildLog()
index 54b934c8e72156ab777a4165085d86bffaf25fab..b6ea1ce43c56901c7e5ee09b47c24b33a80a6e97 100644 (file)
@@ -195,7 +195,7 @@ yy13:
 
     if (!is_target) {
       ins_.push_back(StringPiece(filename, len));
-    } else if (!out_.str_) {
+    } else if (!out_.str()) {
       out_ = StringPiece(filename, len);
     } else if (out_ != StringPiece(filename, len)) {
       *err = "depfile has multiple output paths.";
index 22db4fe70e7579719ab06a504cc52197e3d018b9..50e641d8783a9bcec1f852faed8939076d189399 100644 (file)
@@ -29,8 +29,8 @@ int EditDistance(const StringPiece& s1,
   // Although the algorithm is typically described using an m x n
   // array, only two rows are used at a time, so this implemenation
   // just keeps two separate vectors for those two rows.
-  int m = s1.len_;
-  int n = s2.len_;
+  int m = s1.len();
+  int n = s2.len();
 
   std::vector<int> previous(n + 1);
   std::vector<int> current(n + 1);
@@ -44,11 +44,11 @@ int EditDistance(const StringPiece& s1,
 
     for (int x = 1; x <= n; ++x) {
       if (allow_replacements) {
-        current[x] = min(previous[x-1] + (s1.str_[y-1] == s2.str_[x-1] ? 0 : 1),
-                         min(current[x-1], previous[x])+1);
+        current[x] = min(previous[x-1] + (s1.str()[y-1] == s2.str()[x-1] ?
+            0 : 1), min(current[x-1], previous[x]) + 1);
       }
       else {
-        if (s1.str_[y-1] == s2.str_[x-1])
+        if (s1.str()[y-1] == s2.str()[x-1])
           current[x] = previous[x-1];
         else
           current[x] = min(current[x-1], previous[x]) + 1;
index 81a87652df8a308a8e995d88e5147c124c41cf53..793ea6464cbd3faf61591004dfd685985290ca59 100644 (file)
@@ -41,7 +41,7 @@ string EvalString::Evaluate(Env* env) const {
 void EvalString::AddText(StringPiece text) {
   // Add it to the end of an existing RAW token if possible.
   if (!parsed_.empty() && parsed_.back().second == RAW) {
-    parsed_.back().first.append(text.str_, text.len_);
+    parsed_.back().first.append(text.str(), text.len());
   } else {
     parsed_.push_back(make_pair(text.AsString(), RAW));
   }
index 56584e3407b2a40c20dd5ed42899dab3ea27ef8c..4bf558a221672a992aa1aba6643aaee50445554a 100644 (file)
@@ -292,7 +292,8 @@ bool Edge::LoadDepFile(State* state, DiskInterface* disk_interface,
   // Add all its in-edges.
   for (vector<StringPiece>::iterator i = depfile.ins_.begin();
        i != depfile.ins_.end(); ++i, ++implicit_dep) {
-    if (!CanonicalizePath(const_cast<char*>(i->str_), &i->len_, err))
+    int length = i->len();
+    if (!CanonicalizePath(const_cast<char*>(i->str()), &length, err))
       return false;
 
     Node* node = state->GetNode(*i);
index 88c268108934e3b7fa18013e85efd918308a9818..15e86dacad1cdbe9e5e550ec0d04cf28fa3fd4d5 100644 (file)
@@ -86,7 +86,7 @@ struct hash<std::string> {
 template<>
 struct hash<StringPiece> {
   size_t operator()(StringPiece key) const {
-    return MurmurHash2(key.str_, key.len_);
+    return MurmurHash2(key.str(), key.len());
   }
 };
 
index b3efe22c54670df8a65318c5760f2aa08410319a..48a46b0be0d50bb08ca546ffcc5b0b8fc1d4081d 100644 (file)
@@ -23,8 +23,8 @@
 bool Lexer::Error(const string& message, string* err) {
   // Compute line/column.
   int line = 1;
-  const char* context = input_.str_;
-  for (const char* p = input_.str_; p < last_token_; ++p) {
+  const char* context = input_.str();
+  for (const char* p = input_.str(); p < last_token_; ++p) {
     if (*p == '\n') {
       ++line;
       context = p + 1;
@@ -66,7 +66,7 @@ Lexer::Lexer(const char* input) {
 void Lexer::Start(StringPiece filename, StringPiece input) {
   filename_ = filename;
   input_ = input;
-  ofs_ = input_.str_;
+  ofs_ = input_.str();
   last_token_ = NULL;
 }
 
index ad1153ee7bbce7b541101d7e4329727ffca93818..76679f1ca0a1be0237af11e6f8e28bf2b07c9427 100644 (file)
@@ -46,6 +46,10 @@ struct StringPiece {
     return len_ ? string(str_, len_) : string();
   }
 
+  const char* str() const { return str_; }
+  int len() const { return len_; }
+
+ private:
   const char* str_;
   int len_;
 };