[Webkit-unassigned] [Bug 250676] Use memcpy in SVGPathByteStreamSource::readType

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Jan 24 12:41:01 PST 2023


https://bugs.webkit.org/show_bug.cgi?id=250676

--- Comment #2 from Said Abou-Hallawa <sabouhallawa at apple.com> ---
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.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20230124/1948e0c8/attachment.htm>


More information about the webkit-unassigned mailing list