Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: third_party/WebKit/Source/platform/exported/WebStringUTF8Adaptor.cpp

Issue 1568073002: Reduce string copies in GURL creation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Mojo issues Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2016 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer 11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 12 * in the documentation and/or other materials provided with the
13 * distribution. 13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its 14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from 15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission. 16 * this software without specific prior written permission.
17 * 17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef WebMIDIAccessor_h 31 #include "public/platform/WebStringUTF8Adaptor.h"
32 #define WebMIDIAccessor_h
33 32
34 #include "WebString.h" 33 #include "public/platform/WebString.h"
34 #include "wtf/text/CString.h"
35 #include "wtf/text/WTFString.h"
35 36
36 namespace blink { 37 namespace blink {
37 38
38 class WebMIDIAccessor { 39 WebStringUTF8Adaptor::WebStringUTF8Adaptor(const WebString& string)
39 public: 40 {
40 virtual ~WebMIDIAccessor() { } 41 if (string.isEmpty())
42 return;
43 // 8-bit WTF::Strings are encoded in Latin-1. If |relative| is entirely
44 // ASCII, we luck out and can avoid mallocing a new buffer to hold the
45 // UTF-8 data because UTF-8 and Latin-1 use the same code units for ASCII
46 // code points.
47 const WTF::String& wtfString = string;
48 if (wtfString.is8Bit() && wtfString.containsOnlyASCII()) {
49 m_stringPiece = base::StringPiece(
50 reinterpret_cast<const char*>(wtfString.characters8()),
51 wtfString.length());
michaeln 2016/01/08 22:52:55 drive by: Do you want the adapter to keep the WTF:
brettw 2016/01/08 23:11:21 Maybe, I'm not sure what you mean. It's expected t
52 } else {
53 m_utf8Buffer = wtfString.utf8().buffer();
54 m_stringPiece = base::StringPiece(m_utf8Buffer->data(), m_utf8Buffer->le ngth());
55 }
56 }
41 57
42 virtual void startSession() { } 58 WebStringUTF8Adaptor::~WebStringUTF8Adaptor()
43 virtual void open(unsigned portIndex) { } 59 {
44 // |timeStamp| is measured in milliseconds as Web MIDI spec defines. 60 m_utf8Buffer.reset();
45 virtual void sendMIDIData(unsigned portIndex, const unsigned char* data, siz e_t length, double timeStamp) { } 61 }
46 virtual void clear(unsigned portIndex) { }
47 virtual void close(unsigned portIndex) { }
48 };
49 62
50 } // namespace blink 63 } // namespace blink
51
52 #endif // WebMIDIAccessor_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/blink_platform.gyp ('k') | third_party/WebKit/public/platform/WebString.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698