simplify SkRRect serialization

I think this happens to fix the particular issue in the attached bug.
memcpy() is kind of the swiss army knife as far as strict aliasing is
concerned... you're always allowed to use it.

The generated code for writeToMemory() is unchanged, and
readFromMemory() gets a bit better looking.

BUG=skia:5105

Change-Id: Ib5bf96600f1138650c004ced2d696e9a4ba83ca7
Reviewed-on: https://skia-review.googlesource.com/11682
Reviewed-by: Cary Clark <caryclark@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
This commit is contained in:
Mike Klein 2017-04-06 22:34:59 -04:00 committed by Skia Commit-Bot
parent 3a1ad6fde2
commit ca878ccfb5

View File

@ -456,10 +456,8 @@ void SkRRect::inset(SkScalar dx, SkScalar dy, SkRRect* dst) const {
///////////////////////////////////////////////////////////////////////////////
size_t SkRRect::writeToMemory(void* buffer) const {
SkASSERT(kSizeInMemory == sizeof(SkRect) + sizeof(fRadii));
memcpy(buffer, &fRect, sizeof(SkRect));
memcpy((char*)buffer + sizeof(SkRect), fRadii, sizeof(fRadii));
// Serialize only the rect and corners, but not the derived type tag.
memcpy(buffer, this, kSizeInMemory);
return kSizeInMemory;
}
@ -468,14 +466,10 @@ size_t SkRRect::readFromMemory(const void* buffer, size_t length) {
return 0;
}
SkScalar storage[12];
SkASSERT(sizeof(storage) == kSizeInMemory);
// Deserialize rect and corners, then rederive the type tag.
memcpy(this, buffer, kSizeInMemory);
this->computeType();
// we make a local copy, to ensure alignment before we cast
memcpy(storage, buffer, kSizeInMemory);
this->setRectRadii(*(const SkRect*)&storage[0],
(const SkVector*)&storage[4]);
return kSizeInMemory;
}