[Cocoa] Clean up / optimize ResourceResponse::platformLazyInit(InitLevel)
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Jun 2016 02:59:54 +0000 (02:59 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Jun 2016 02:59:54 +0000 (02:59 +0000)
commit7bc94e8b64706bea21d96a36a12d112f3ce8571a
treebf4ab87f2e37e4ada2c7d2b1aed12df419e3ba61
parent0d7f557b44081d7d440c6c4c0866b6b4c8343e3b
[Cocoa] Clean up / optimize ResourceResponse::platformLazyInit(InitLevel)
https://bugs.webkit.org/show_bug.cgi?id=158809

Reviewed by Darin Adler.

Source/WebCore:

Clean up / optimize ResourceResponse::platformLazyInit(InitLevel).

* platform/network/HTTPParsers.cpp:
(WebCore::extractReasonPhraseFromHTTPStatusLine):
* platform/network/HTTPParsers.h:
Have extractReasonPhraseFromHTTPStatusLine() return an AtomicString as the
Reason is stored as an AtomicString on ResourceResponse. Have the
implementation use StringView::subString()::toAtomicString().

* platform/network/cocoa/ResourceResponseCocoa.mm:
(WebCore::stripLeadingAndTrailingDoubleQuote):
Move the stripLeadingAndTrailingDoubleQuote logic from platformLazyInit()
to its own function. Have it use StringView::subString()::toAtomicString()
to avoid unnecessarily atomizing the textEncodingName that has surrounding
double-quotes.

(WebCore::initializeHTTPHeaders):
Move HTTP headers initialization to its own function for clarity.

(WebCore::extractHTTPStatusText):
Move HTTP status Text extraction to its own function for clarity.

(WebCore::ResourceResponse::platformLazyInit):
- The function is streamlined a bit because most of the logic was moved
  into separate functions.
- Drop unnecessary (initLevel >= CommonFieldsOnly) check in the first
  if case and replace with an assertion. This function is always called
  with CommonFieldsOnly or above (AllFields).
- Drop unnecessary (m_initLevel < AllFields) check in the second if
  case as this is always true. If not, we would have returned early
  at the beginning of the function when checking
  m_initLevel >= initLevel.
- Use AutodrainedPool instead of NSAutoreleasePool for convenience and have
  only 1 pool instead of 2.
- Drop unnecessary copyNSURLResponseStatusLine() function and call directly
  CFHTTPMessageCopyResponseStatusLine() since we already have a
  CFHTTPMessageRef at the call site.

Source/WTF:

Add toAtomicString() method to StringView to avoid having to call toString()
and then atomizing the String at call sites.

* wtf/text/StringView.h:
(WTF::StringView::toAtomicString):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202121 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WTF/ChangeLog
Source/WTF/wtf/text/StringView.h
Source/WebCore/ChangeLog
Source/WebCore/platform/network/HTTPParsers.cpp
Source/WebCore/platform/network/HTTPParsers.h
Source/WebCore/platform/network/cocoa/ResourceResponseCocoa.mm