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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/exported/WebStringUTF8Adaptor.cpp
diff --git a/third_party/WebKit/public/platform/WebMIDIAccessor.h b/third_party/WebKit/Source/platform/exported/WebStringUTF8Adaptor.cpp
similarity index 61%
copy from third_party/WebKit/public/platform/WebMIDIAccessor.h
copy to third_party/WebKit/Source/platform/exported/WebStringUTF8Adaptor.cpp
index a31cfda7c842b869a9ed1767cbf6ceff4a3660c2..6383f71e76621d912b270b96cdc2a87207268221 100644
--- a/third_party/WebKit/public/platform/WebMIDIAccessor.h
+++ b/third_party/WebKit/Source/platform/exported/WebStringUTF8Adaptor.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Google Inc. All rights reserved.
+ * Copyright (C) 2016 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -28,25 +28,36 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef WebMIDIAccessor_h
-#define WebMIDIAccessor_h
+#include "public/platform/WebStringUTF8Adaptor.h"
-#include "WebString.h"
+#include "public/platform/WebString.h"
+#include "wtf/text/CString.h"
+#include "wtf/text/WTFString.h"
namespace blink {
-class WebMIDIAccessor {
-public:
- virtual ~WebMIDIAccessor() { }
+WebStringUTF8Adaptor::WebStringUTF8Adaptor(const WebString& string)
+{
+ if (string.isEmpty())
+ return;
+ // 8-bit WTF::Strings are encoded in Latin-1. If |relative| is entirely
+ // ASCII, we luck out and can avoid mallocing a new buffer to hold the
+ // UTF-8 data because UTF-8 and Latin-1 use the same code units for ASCII
+ // code points.
+ const WTF::String& wtfString = string;
+ if (wtfString.is8Bit() && wtfString.containsOnlyASCII()) {
+ m_stringPiece = base::StringPiece(
+ reinterpret_cast<const char*>(wtfString.characters8()),
+ 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
+ } else {
+ m_utf8Buffer = wtfString.utf8().buffer();
+ m_stringPiece = base::StringPiece(m_utf8Buffer->data(), m_utf8Buffer->length());
+ }
+}
- virtual void startSession() { }
- virtual void open(unsigned portIndex) { }
- // |timeStamp| is measured in milliseconds as Web MIDI spec defines.
- virtual void sendMIDIData(unsigned portIndex, const unsigned char* data, size_t length, double timeStamp) { }
- virtual void clear(unsigned portIndex) { }
- virtual void close(unsigned portIndex) { }
-};
+WebStringUTF8Adaptor::~WebStringUTF8Adaptor()
+{
+ m_utf8Buffer.reset();
+}
} // namespace blink
-
-#endif // WebMIDIAccessor_h
« 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