From: Mike Klein Date: Fri, 7 Apr 2017 02:34:59 +0000 (-0400) Subject: simplify SkRRect serialization X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~46^2~99 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ca878ccfb5d514b4e7baea9e6d410b0085211b40;p=platform%2Fupstream%2FlibSkiaSharp.git 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 Commit-Queue: Mike Klein --- diff --git a/src/core/SkRRect.cpp b/src/core/SkRRect.cpp index 2ed8bbf..824ee62 100644 --- a/src/core/SkRRect.cpp +++ b/src/core/SkRRect.cpp @@ -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); - - // we make a local copy, to ensure alignment before we cast - memcpy(storage, buffer, kSizeInMemory); + // Deserialize rect and corners, then rederive the type tag. + memcpy(this, buffer, kSizeInMemory); + this->computeType(); - this->setRectRadii(*(const SkRect*)&storage[0], - (const SkVector*)&storage[4]); return kSizeInMemory; }