aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-31 16:22:57 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-31 16:22:57 +0000
commitc6d3c444ca76feba5a8937dbc80626ade5347275 (patch)
treef0449476185aa082fc75f2bb6192465ab6ceff55 /include
parent0a74106aaae65151715482b6d0e35906b8a4c9e5 (diff)
Have peek32 return uint32_t& to make it harder to look at more than 4 bytes.
BUG=skia: R=reed@google.com, robertphillips@google.com Author: mtklein@google.com Review URL: https://codereview.chromium.org/145053003 git-svn-id: http://skia.googlecode.com/svn/trunk@13265 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r--include/core/SkWriter32.h31
1 files changed, 16 insertions, 15 deletions
diff --git a/include/core/SkWriter32.h b/include/core/SkWriter32.h
index 6bb59c5dbc..b193cbe7c4 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(); }