Changeset 230338 in webkit


Ignore:
Timestamp:
Apr 6, 2018 10:45:57 AM (6 years ago)
Author:
dbates@webkit.org
Message:

Have class Exception take String by value instead of a String&&
https://bugs.webkit.org/show_bug.cgi?id=184360

Reviewed by Alexey Proskuryakov.

For convenience support instantiating an Exception with either an lvalue String or
rvalue String.

Although it can be argued that having Exception take a String by value instead of String&&
can lead to missed opportunities to WTFMove() a String object into Exception such mistakes
are just that, missed opportunities. That is, correctness is not affected and we may perform
an unnecessary ref/deref of the underlying StringImpl when instantiating an Exception. If
such missed opportunities show up in profiles and such mistakes happen often then we can
re-evaluate the decision to have Exception take a String by value.

  • Modules/cache/DOMCache.cpp:

(WebCore::DOMCache::put): Simplify code now that Exception takes a String by value.

  • Modules/fetch/FetchResponse.cpp:

(WebCore::FetchResponse::BodyLoader::didFail): Ditto.

  • Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:

(WebCore::LibWebRTCMediaEndpoint::createSessionDescriptionFailed): Move String into Exception to avoid an
unnecessary ref/de-ref.
(WebCore::LibWebRTCMediaEndpoint::setLocalSessionDescriptionFailed): Ditto.
(WebCore::LibWebRTCMediaEndpoint::setRemoteSessionDescriptionFailed): Ditto.

  • dom/Exception.h:

(WebCore::Exception::Exception): Take String by value. Also use uniform initializer syntax.

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r230334 r230338  
     12018-04-06  Daniel Bates  <dabates@apple.com>
     2
     3        Have class Exception take String by value instead of a String&&
     4        https://bugs.webkit.org/show_bug.cgi?id=184360
     5
     6        Reviewed by Alexey Proskuryakov.
     7
     8        For convenience support instantiating an Exception with either an lvalue String or
     9        rvalue String.
     10
     11        Although it can be argued that having Exception take a String by value instead of String&&
     12        can lead to missed opportunities to WTFMove() a String object into Exception such mistakes
     13        are just that, missed opportunities. That is, correctness is not affected and we may perform
     14        an unnecessary ref/deref of the underlying StringImpl when instantiating an Exception. If
     15        such missed opportunities show up in profiles and such mistakes happen often then we can
     16        re-evaluate the decision to have Exception take a String by value.
     17
     18        * Modules/cache/DOMCache.cpp:
     19        (WebCore::DOMCache::put): Simplify code now that Exception takes a String by value.
     20        * Modules/fetch/FetchResponse.cpp:
     21        (WebCore::FetchResponse::BodyLoader::didFail): Ditto.
     22        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
     23        (WebCore::LibWebRTCMediaEndpoint::createSessionDescriptionFailed): Move String into Exception to avoid an
     24        unnecessary ref/de-ref.
     25        (WebCore::LibWebRTCMediaEndpoint::setLocalSessionDescriptionFailed): Ditto.
     26        (WebCore::LibWebRTCMediaEndpoint::setRemoteSessionDescriptionFailed): Ditto.
     27        * dom/Exception.h:
     28        (WebCore::Exception::Exception): Take String by value. Also use uniform initializer syntax.
     29
    1302018-04-06  Antti Koivisto  <antti@apple.com>
    231
  • trunk/Source/WebCore/Modules/cache/DOMCache.cpp

    r228326 r230338  
    322322
    323323    if (response->loadingError()) {
    324         promise.reject(Exception { TypeError, String { response->loadingError()->localizedDescription() } });
     324        promise.reject(Exception { TypeError, response->loadingError()->localizedDescription() });
    325325        return;
    326326    }
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp

    r228199 r230338  
    242242
    243243    if (auto responseCallback = WTFMove(m_responseCallback))
    244         responseCallback(Exception { TypeError, String(error.localizedDescription()) });
     244        responseCallback(Exception { TypeError, error.localizedDescription() });
    245245
    246246    if (auto consumeDataCallback = WTFMove(m_consumeDataCallback))
    247         consumeDataCallback(Exception { TypeError, String(error.localizedDescription()) });
     247        consumeDataCallback(Exception { TypeError, error.localizedDescription() });
    248248
    249249#if ENABLE(STREAMS_API)
  • trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp

    r230152 r230338  
    915915            return;
    916916        if (protectedThis->m_isInitiator)
    917             protectedThis->m_peerConnectionBackend.createOfferFailed(Exception { OperationError, String(error) });
     917            protectedThis->m_peerConnectionBackend.createOfferFailed(Exception { OperationError, WTFMove(error) });
    918918        else
    919             protectedThis->m_peerConnectionBackend.createAnswerFailed(Exception { OperationError, String(error) });
     919            protectedThis->m_peerConnectionBackend.createAnswerFailed(Exception { OperationError, WTFMove(error) });
    920920    });
    921921}
     
    936936        if (protectedThis->isStopped())
    937937            return;
    938         protectedThis->m_peerConnectionBackend.setLocalDescriptionFailed(Exception { OperationError, String(error) });
     938        protectedThis->m_peerConnectionBackend.setLocalDescriptionFailed(Exception { OperationError, WTFMove(error) });
    939939    });
    940940}
     
    955955        if (protectedThis->isStopped())
    956956            return;
    957         protectedThis->m_peerConnectionBackend.setRemoteDescriptionFailed(Exception { OperationError, String(error) });
     957        protectedThis->m_peerConnectionBackend.setRemoteDescriptionFailed(Exception { OperationError, WTFMove(error) });
    958958    });
    959959}
  • trunk/Source/WebCore/dom/Exception.h

    r221414 r230338  
    3434class Exception {
    3535public:
    36     explicit Exception(ExceptionCode, String&& = { });
     36    explicit Exception(ExceptionCode, String = { });
    3737
    3838    ExceptionCode code() const { return m_code; }
     
    5252Exception isolatedCopy(Exception&&);
    5353
    54 inline Exception::Exception(ExceptionCode code, String&& message)
    55     : m_code(code)
    56     , m_message(WTFMove(message))
     54inline Exception::Exception(ExceptionCode code, String message)
     55    : m_code { code }
     56    , m_message { WTFMove(message) }
    5757{
    5858}
Note: See TracChangeset for help on using the changeset viewer.