Changeset 273185 in webkit


Ignore:
Timestamp:
Feb 19, 2021 4:55:59 PM (17 months ago)
Author:
Patrick Angle
Message:

Web Inspector: Implement Grid Overlay "Show line names" drawing
https://bugs.webkit.org/show_bug.cgi?id=222006
<rdar://problem/74409722>

Reviewed by BJ Burg.

Followup for r273155 related to WTF::String::append performance.

  • inspector/InspectorOverlay.cpp:

(WebCore::gridLineNames):

  • Use const Vector<String>& to avoid copying the entire Vector and churning the reference count on the strings.

(WebCore::InspectorOverlay::drawGridOverlay):

  • Use WTF::StringBuilder instead of WTF::String::append for line label contents.
Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r273184 r273185  
     12021-02-19  Patrick Angle  <pangle@apple.com>
     2
     3        Web Inspector: Implement Grid Overlay "Show line names" drawing
     4        https://bugs.webkit.org/show_bug.cgi?id=222006
     5        <rdar://problem/74409722>
     6
     7        Reviewed by BJ Burg.
     8
     9        Followup for r273155 related to `WTF::String::append` performance.
     10
     11        * inspector/InspectorOverlay.cpp:
     12        (WebCore::gridLineNames):
     13        - Use `const Vector<String>&` to avoid copying the entire Vector and churning the reference count on the strings.
     14        (WebCore::InspectorOverlay::drawGridOverlay):
     15        - Use `WTF::StringBuilder` instead of `WTF::String::append` for line label contents.
     16
    1172021-02-19  Wenson Hsieh  <wenson_hsieh@apple.com>
    218
  • trunk/Source/WebCore/inspector/InspectorOverlay.cpp

    r273155 r273185  
    13391339   
    13401340    OrderedNamedGridLinesMap combinedGridLineNames;
    1341     auto appendLineNames = [&](unsigned index, Vector<String> newNames) {
     1341    auto appendLineNames = [&](unsigned index, const Vector<String>& newNames) {
    13421342        if (combinedGridLineNames.contains(index)) {
    13431343            auto names = combinedGridLineNames.take(index);
     
    14791479        context.strokePath(columnPaths);
    14801480       
    1481         Vector<String> lineLabelParts;
    1482         if (gridOverlay.config.showLineNumbers) {
    1483             lineLabelParts.append(String::number(i + 1));
    1484             lineLabelParts.append(String::number(-static_cast<int>(columnPositions.size() - i)));
    1485         }
    1486         if (gridOverlay.config.showLineNames && columnLineNames.contains(i))
    1487             lineLabelParts.appendVector(columnLineNames.get(i));
    1488         if (lineLabelParts.size()) {
    1489             auto lineLabel = lineLabelParts[0];
    1490             for (size_t i = 1; i < lineLabelParts.size(); ++i) {
    1491                 lineLabel.append(thinSpace);
    1492                 lineLabel.append(bullet);
    1493                 lineLabel.append(thinSpace);
    1494                 lineLabel.append(lineLabelParts[i]);
     1481        StringBuilder lineLabel;
     1482        if (gridOverlay.config.showLineNumbers)
     1483            lineLabel.append(i + 1, thinSpace, bullet, thinSpace, -static_cast<int>(columnPositions.size() - i));
     1484        if (gridOverlay.config.showLineNames && columnLineNames.contains(i)) {
     1485            for (auto lineName : columnLineNames.get(i)) {
     1486                if (!lineLabel.isEmpty())
     1487                    lineLabel.append(thinSpace, bullet, thinSpace);
     1488                lineLabel.append(lineName);
    14951489            }
    1496             // FIXME: <webkit.org/b/221972> Layout labels can be drawn outside the viewport, and a best effort should be made to keep them in the viewport while the grid is in the viewport.
    1497             drawLayoutLabel(context, lineLabel, FloatPoint(labelX, gridBoundingBox.y()), LabelArrowDirection::Down);
    1498         }
     1490        }
     1491        // FIXME: <webkit.org/b/221972> Layout labels can be drawn outside the viewport, and a best effort should be made to keep them in the viewport while the grid is in the viewport.
     1492        if (!lineLabel.isEmpty())
     1493            drawLayoutLabel(context, lineLabel.toString(), FloatPoint(labelX, gridBoundingBox.y()), LabelArrowDirection::Down);
    14991494    }
    15001495
     
    15441539        context.strokePath(rowPaths);
    15451540       
    1546         Vector<String> lineLabelParts;
    1547         if (gridOverlay.config.showLineNumbers) {
    1548             lineLabelParts.append(String::number(i + 1));
    1549             lineLabelParts.append(String::number(-static_cast<int>(rowPositions.size() - i)));
    1550         }
    1551         if (gridOverlay.config.showLineNames && rowLineNames.contains(i))
    1552             lineLabelParts.appendVector(rowLineNames.get(i));
    1553         if (lineLabelParts.size()) {
    1554             auto lineLabel = lineLabelParts[0];
    1555             for (size_t i = 1; i < lineLabelParts.size(); ++i) {
    1556                 lineLabel.append(thinSpace);
    1557                 lineLabel.append(bullet);
    1558                 lineLabel.append(thinSpace);
    1559                 lineLabel.append(lineLabelParts[i]);
     1541        StringBuilder lineLabel;
     1542        if (gridOverlay.config.showLineNumbers)
     1543            lineLabel.append(i + 1, thinSpace, bullet, thinSpace, -static_cast<int>(rowPositions.size() - i));
     1544        if (gridOverlay.config.showLineNames && rowLineNames.contains(i)) {
     1545            for (auto lineName : rowLineNames.get(i)) {
     1546                if (!lineLabel.isEmpty())
     1547                    lineLabel.append(thinSpace, bullet, thinSpace);
     1548                lineLabel.append(lineName);
    15601549            }
    1561             // FIXME: <webkit.org/b/221972> Layout labels can be drawn outside the viewport, and a best effort should be made to keep them in the viewport while the grid is in the viewport.
    1562             drawLayoutLabel(context, lineLabel, FloatPoint(gridBoundingBox.x(), labelY), LabelArrowDirection::Right);
    1563         }
     1550        }
     1551        // FIXME: <webkit.org/b/221972> Layout labels can be drawn outside the viewport, and a best effort should be made to keep them in the viewport while the grid is in the viewport.
     1552        if (!lineLabel.isEmpty())
     1553            drawLayoutLabel(context, lineLabel.toString(), FloatPoint(gridBoundingBox.x(), labelY), LabelArrowDirection::Right);
    15641554    }
    15651555   
Note: See TracChangeset for help on using the changeset viewer.