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

Unified Diff: include/core/SkWriter32.h

Issue 145053003: Have peek32 return uint32_t& to make it harder to look at more than 4 bytes. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: read write at 32 Created 6 years, 11 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
« no previous file with comments | « no previous file | src/core/SkPictureRecord.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkWriter32.h
diff --git a/include/core/SkWriter32.h b/include/core/SkWriter32.h
index 6bb59c5dbc703f95f29f9645332747a519b32921..b193cbe7c407663f7a82a613b8a65b5e1e637a47 100644
--- a/include/core/SkWriter32.h
+++ b/include/core/SkWriter32.h
@@ -79,19 +79,9 @@ public:
return p;
}
- // return the address of the 4byte int at the specified offset (which must
- // be a multiple of 4. This does not allocate any new space, so the returned
- // address is only valid for 1 int.
- uint32_t* peek32(size_t offset) {
- SkASSERT(SkAlign4(offset) == offset);
- const int count = SkToInt(offset/4);
- SkASSERT(count < fCount);
-
- if (count < this->externalCount()) {
- return fExternal + count;
- }
- return &fInternal[count - this->externalCount()];
- }
+ // Read or write 4 bytes at offset, which must be a multiple of 4 <= size().
+ uint32_t read32At(size_t offset) { return this->atOffset(offset); }
+ void write32At(size_t offset, uint32_t val) { this->atOffset(offset) = val; }
bool writeBool(bool value) {
this->write32(value);
@@ -215,8 +205,7 @@ public:
/**
* Move the cursor back to offset bytes from the beginning.
- * This has the same restrictions as peek32: offset must be <= size() and
- * offset must be a multiple of 4.
+ * offset must be a multiple of 4 no greater than size().
*/
void rewindToOffset(size_t offset) {
SkASSERT(SkAlign4(offset) == offset);
@@ -249,6 +238,18 @@ public:
}
private:
+ uint32_t& atOffset(size_t offset) {
+ SkASSERT(SkAlign4(offset) == offset);
+ const int count = SkToInt(offset/4);
+ SkASSERT(count < fCount);
+
+ if (count < this->externalCount()) {
+ return fExternal[count];
+ }
+ return fInternal[count - this->externalCount()];
+ }
+
+
// Number of uint32_t written into fExternal. <= fExternalLimit.
int externalCount() const { return fCount - fInternal.count(); }
« no previous file with comments | « no previous file | src/core/SkPictureRecord.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698