Title: [150358] trunk/Source/WebCore
Revision
150358
Author
[email protected]
Date
2013-05-19 17:04:57 -0700 (Sun, 19 May 2013)

Log Message

[Mac] Improve string use in PasteboardMac
https://bugs.webkit.org/show_bug.cgi?id=116418

Reviewed by Sam Weinig.

Did a Ben Poulain all over this file.

* platform/mac/PasteboardMac.mm:
(WebCore::Pasteboard::plainText): Add the newline separately to the string builder.
Prepending it to the string first just does more allocations for no good reason.
(WebCore::Pasteboard::documentFragment): Use emptyString() instead of "" and use
ASCIILiteral where appropriate.
(WebCore::cocoaTypeFromHTMLClipboardType): More ASCIILiteral.
(WebCore::Pasteboard::clear): Use early return instead of a nested if here.
Use emptyString() instead of "".
(WebCore::addHTMLClipboardTypesForCocoaType): More ASCIILiteral.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (150357 => 150358)


--- trunk/Source/WebCore/ChangeLog	2013-05-19 23:56:04 UTC (rev 150357)
+++ trunk/Source/WebCore/ChangeLog	2013-05-20 00:04:57 UTC (rev 150358)
@@ -1,3 +1,22 @@
+2013-05-19  Darin Adler  <[email protected]>
+
+        [Mac] Improve string use in PasteboardMac
+        https://bugs.webkit.org/show_bug.cgi?id=116418
+
+        Reviewed by Sam Weinig.
+
+        Did a Ben Poulain all over this file.
+
+        * platform/mac/PasteboardMac.mm:
+        (WebCore::Pasteboard::plainText): Add the newline separately to the string builder.
+        Prepending it to the string first just does more allocations for no good reason.
+        (WebCore::Pasteboard::documentFragment): Use emptyString() instead of "" and use
+        ASCIILiteral where appropriate.
+        (WebCore::cocoaTypeFromHTMLClipboardType): More ASCIILiteral.
+        (WebCore::Pasteboard::clear): Use early return instead of a nested if here.
+        Use emptyString() instead of "".
+        (WebCore::addHTMLClipboardTypesForCocoaType): More ASCIILiteral.
+
 2013-05-19  Anders Carlsson  <[email protected]>
 
         Remove link prerendering code

Modified: trunk/Source/WebCore/platform/mac/PasteboardMac.mm (150357 => 150358)


--- trunk/Source/WebCore/platform/mac/PasteboardMac.mm	2013-05-19 23:56:04 UTC (rev 150357)
+++ trunk/Source/WebCore/platform/mac/PasteboardMac.mm	2013-05-20 00:04:57 UTC (rev 150358)
@@ -390,8 +390,11 @@
         Vector<String> pathnames;
         platformStrategies()->pasteboardStrategy()->getPathnamesForType(pathnames, NSFilenamesPboardType, m_pasteboardName);
         StringBuilder builder;
-        for (size_t i = 0; i < pathnames.size(); i++)
-            builder.append(i ? "\n" + pathnames[i] : pathnames[i]);
+        for (size_t i = 0; i < pathnames.size(); i++) {
+            if (i)
+                builder.append('\n');
+            builder.append(pathnames[i]);
+        }
         string = builder.toString();
         return [string precomposedStringWithCanonicalMapping];
     }
@@ -554,7 +557,7 @@
             }
         }
         if ([HTMLString length] != 0 &&
-            (fragment = createFragmentFromMarkup(frame->document(), HTMLString, "", DisallowScriptingAndPluginContent)))
+            (fragment = createFragmentFromMarkup(frame->document(), HTMLString, emptyString(), DisallowScriptingAndPluginContent)))
             return fragment.release();
     }
 
@@ -567,15 +570,15 @@
         return fragment.release();
 
     if (types.contains(String(NSTIFFPboardType)) &&
-        (fragment = documentFragmentWithImageResource(frame, ArchiveResource::create(platformStrategies()->pasteboardStrategy()->bufferForType(NSTIFFPboardType, m_pasteboardName), uniqueURLWithRelativePart(@"image.tiff"), "image/tiff", "", ""))))
+        (fragment = documentFragmentWithImageResource(frame, ArchiveResource::create(platformStrategies()->pasteboardStrategy()->bufferForType(NSTIFFPboardType, m_pasteboardName), uniqueURLWithRelativePart(@"image.tiff"), ASCIILiteral("image/tiff"), emptyString(), emptyString()))))
         return fragment.release();
 
     if (types.contains(String(NSPDFPboardType)) &&
-        (fragment = documentFragmentWithImageResource(frame, ArchiveResource::create(platformStrategies()->pasteboardStrategy()->bufferForType(NSPDFPboardType, m_pasteboardName).get(), uniqueURLWithRelativePart(@"application.pdf"), "application/pdf", "", ""))))
+        (fragment = documentFragmentWithImageResource(frame, ArchiveResource::create(platformStrategies()->pasteboardStrategy()->bufferForType(NSPDFPboardType, m_pasteboardName).get(), uniqueURLWithRelativePart(@"application.pdf"), ASCIILiteral("application/pdf"), emptyString(), emptyString()))))
         return fragment.release();
 
     if (types.contains(String(kUTTypePNG)) &&
-        (fragment = documentFragmentWithImageResource(frame, ArchiveResource::create(platformStrategies()->pasteboardStrategy()->bufferForType(String(kUTTypePNG), m_pasteboardName), uniqueURLWithRelativePart(@"image.png"), "image/png", "", ""))))
+        (fragment = documentFragmentWithImageResource(frame, ArchiveResource::create(platformStrategies()->pasteboardStrategy()->bufferForType(String(kUTTypePNG), m_pasteboardName), uniqueURLWithRelativePart(@"image.png"), ASCIILiteral("image/png"), emptyString(), emptyString()))))
         return fragment.release();
 
     if (types.contains(String(NSURLPboardType))) {
@@ -620,9 +623,9 @@
     String qType = type.lower();
 
     if (qType == "text")
-        qType = "text/plain";
+        qType = ASCIILiteral("text/plain");
     if (qType == "url")
-        qType = "text/uri-list";
+        qType = ASCIILiteral("text/uri-list");
 
     // Ignore any trailing charset - JS strings are Unicode, which encapsulates the charset issue
     if (qType == "text/plain" || qType.startsWith("text/plain;"))
@@ -650,8 +653,9 @@
 void Pasteboard::clear(const String& type)
 {
     String cocoaType = cocoaTypeFromHTMLClipboardType(type);
-    if (!cocoaType.isEmpty())
-        platformStrategies()->pasteboardStrategy()->setStringForType("", cocoaType, m_pasteboardName);
+    if (cocoaType.isEmpty())
+        return;
+    platformStrategies()->pasteboardStrategy()->setStringForType(emptyString(), cocoaType, m_pasteboardName);
 }
 
 static Vector<String> absoluteURLsFromPasteboardFilenames(const String& pasteboardName, bool _onlyFirstURL_ = false)
@@ -734,11 +738,11 @@
 {
     // UTI may not do these right, so make sure we get the right, predictable result
     if (cocoaType == String(NSStringPboardType)) {
-        resultTypes.add("text/plain");
+        resultTypes.add(ASCIILiteral("text/plain"));
         return;
     }
     if (cocoaType == String(NSURLPboardType)) {
-        resultTypes.add("text/uri-list");
+        resultTypes.add(ASCIILiteral("text/uri-list"));
         return;
     }
     if (cocoaType == String(NSFilenamesPboardType)) {
@@ -750,8 +754,8 @@
         if (!fileList.isEmpty()) {
             // It is unknown if NSFilenamesPboardType always implies NSURLPboardType in Cocoa,
             // but NSFilenamesPboardType should imply both 'text/uri-list' and 'Files'
-            resultTypes.add("text/uri-list");
-            resultTypes.add("Files");
+            resultTypes.add(ASCIILiteral("text/uri-list"));
+            resultTypes.add(ASCIILiteral("Files"));
         }
         return;
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to