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

Unified Diff: base/pickle.cc

Issue 290173008: Refactor PickleIterator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
Index: base/pickle.cc
===================================================================
--- base/pickle.cc (revision 271871)
+++ base/pickle.cc (working copy)
@@ -19,8 +19,9 @@
static const size_t kCapacityReadOnly = static_cast<size_t>(-1);
PickleIterator::PickleIterator(const Pickle& pickle)
- : read_ptr_(pickle.payload()),
- read_end_ptr_(pickle.end_of_payload()) {
+ : payload_ptr_(pickle.payload()),
+ read_index_(0),
+ end_index_(pickle.payload_size()) {
}
template <typename Type>
@@ -35,23 +36,29 @@
return true;
}
+inline void PickleIterator::Advance(size_t size) {
jar (doing other things) 2014/05/23 21:22:04 I *think* all (both?) calls to this method pass in
halyavin 2014/05/26 07:43:02 Done.
+ if (end_index_ - read_index_ < size) {
+ read_index_ = end_index_;
+ } else {
+ read_index_ += size;
+ }
+}
+
template<typename Type>
inline const char* PickleIterator::GetReadPointerAndAdvance() {
- const char* current_read_ptr = read_ptr_;
- if (read_ptr_ + sizeof(Type) > read_end_ptr_)
+ if (sizeof(Type) > end_index_ - read_index_)
return NULL;
jar (doing other things) 2014/05/23 21:22:04 I agree that you perfectly translate the existing
halyavin 2014/05/26 07:43:02 Looks reasonable. Let us see what happens.
- if (sizeof(Type) < sizeof(uint32))
- read_ptr_ += AlignInt(sizeof(Type), sizeof(uint32));
- else
- read_ptr_ += sizeof(Type);
+ const char* current_read_ptr = payload_ptr_ + read_index_;
+ Advance(AlignInt(sizeof(Type), sizeof(uint32_t)));
jar (doing other things) 2014/05/23 21:22:04 I think the precise translation of the old code wo
halyavin 2014/05/26 07:43:02 It was a bug since sizeof(Type) may not be divisib
return current_read_ptr;
}
const char* PickleIterator::GetReadPointerAndAdvance(int num_bytes) {
- if (num_bytes < 0 || read_end_ptr_ - read_ptr_ < num_bytes)
+ if (num_bytes < 0 ||
+ end_index_ - read_index_ < static_cast<size_t>(num_bytes))
return NULL;
jar (doing other things) 2014/05/23 21:22:04 Here again I *wonder* if we should advance, making
halyavin 2014/05/26 07:43:02 Done.
- const char* current_read_ptr = read_ptr_;
- read_ptr_ += AlignInt(num_bytes, sizeof(uint32));
+ const char* current_read_ptr = payload_ptr_ + read_index_;
+ Advance(AlignInt(num_bytes, sizeof(uint32_t)));
return current_read_ptr;
}
@@ -332,6 +339,6 @@
char* write = mutable_payload() + write_offset_;
memcpy(write, data, length);
memset(write + length, 0, data_len - length);
- header_->payload_size = static_cast<uint32>(write_offset_ + length);
+ header_->payload_size = static_cast<uint32>(new_size);
jar (doing other things) 2014/05/23 21:22:04 Would this change alone, which keeps payload_size
halyavin 2014/05/26 07:43:02 No, because the other side of IPC connection might
jar (doing other things) 2014/05/27 23:29:34 Isn't this the side that is writing into a pickle,
halyavin 2014/05/28 07:45:12 It doesn't. I meant that we still need to check al
jar (doing other things) 2014/05/29 01:51:16 FWIW: I checked... PNaCL uses its own IPC, and han
write_offset_ = new_size;
}

Powered by Google App Engine
This is Rietveld 408576698