| Summary: | Use memcpy in SVGPathByteStreamSource::readType | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Ahmad Saleem <ahmad.saleem792> |
| Component: | SVG | Assignee: | Chris Dumez <cdumez> |
| Status: | RESOLVED FIXED | ||
| Severity: | Normal | CC: | sabouhallawa, webkit-bug-importer, zimmermann |
| Priority: | P2 | Keywords: | InRadar |
| Version: | WebKit Nightly Build | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
|
Description
Ahmad Saleem
2023-01-16 05:24:17 PST
I think there is no much saving in the Blink's commit. This function just reads bool, short or float. So the for-loop in SVGPathByteStreamSource::readType() runs 1, 2 or 4 times. In my opinion using memcpy is just a cleaner solution and nice refactoring but it is not a perf or code size optimization.
So if we want to clean this area, I would suggest something like that instead:
// SVGPathByteStreamSource.h
template<typename DataType>
DataType readType()
{
DataType data;
size_t dataSize = sizeof(DataType);
ASSERT(m_streamCurrent + dataSize <= m_streamEnd);
memcpy(&data, m_streamCurrent, dataSize);
m_streamCurrent += dataSize;
return data;
}
// SVGPathByteStreamBuilder.h
template<typename DataType>
void writeType(DataType data)
{
union {
DataType value;
unsigned char bytes[sizeof(DataType)];
} ByteType;
ByteType type = { data };
size_t typeSize = sizeof(ByteType);
for (size_t i = 0; i < typeSize; ++i)
m_byteStream.append(type.bytes[i]);
}
And we can get rid of BoolByte, FloatByte and UnsignedShortByte.
Pull request: https://github.com/WebKit/WebKit/pull/17264 Committed 267523@main (e2aa0c20fc47): <https://commits.webkit.org/267523@main> Reviewed commits have been landed. Closing PR #17264 and removing active labels. |