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

Side by Side Diff: public/platform/WebURL.h

Issue 20135002: Optimize WebURL -> GURL conversions (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove operator< Created 7 years, 5 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 | Annotate | Revision Log
« public/platform/WebString.h ('K') | « public/platform/WebString.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 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
(...skipping 14 matching lines...) Expand all
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 WebURL_h 31 #ifndef WebURL_h
32 #define WebURL_h 32 #define WebURL_h
33 33
34 #include "WebCString.h" 34 #include "WebCString.h"
35 #include "WebString.h"
35 #include <url/url_parse.h> 36 #include <url/url_parse.h>
36 37
37 #if WEBKIT_IMPLEMENTATION 38 #if WEBKIT_IMPLEMENTATION
38 namespace WebCore { class KURL; } 39 namespace WebCore { class KURL; }
39 #else 40 #else
40 #include <url/gurl.h> 41 #include <url/gurl.h>
41 #endif 42 #endif
42 43
43 namespace WebKit { 44 namespace WebKit {
44 45
45 class WebURL { 46 class WebURL {
46 public: 47 public:
47 ~WebURL() 48 ~WebURL()
48 { 49 {
49 } 50 }
50 51
51 WebURL() : m_isValid(false) 52 WebURL()
53 : m_isValid(false)
52 { 54 {
53 } 55 }
54 56
55 WebURL(const WebCString& spec, const url_parse::Parsed& parsed, bool isValid ) 57 WebURL(const WebURL& url)
56 : m_spec(spec) 58 : m_string(url.m_string)
57 , m_parsed(parsed) 59 , m_parsed(url.m_parsed)
58 , m_isValid(isValid) 60 , m_isValid(url.m_isValid)
59 { 61 {
60 } 62 }
61 63
62 WebURL(const WebURL& s) 64 WebURL& operator=(const WebURL& url)
63 : m_spec(s.m_spec)
64 , m_parsed(s.m_parsed)
65 , m_isValid(s.m_isValid)
66 { 65 {
67 } 66 m_string = url.m_string;
68 67 m_parsed = url.m_parsed;
69 WebURL& operator=(const WebURL& s) 68 m_isValid = url.m_isValid;
70 {
71 m_spec = s.m_spec;
72 m_parsed = s.m_parsed;
73 m_isValid = s.m_isValid;
74 return *this; 69 return *this;
75 } 70 }
76 71
77 void assign(const WebCString& spec, const url_parse::Parsed& parsed, bool is Valid) 72 WebCString spec() const
78 { 73 {
79 m_spec = spec; 74 return m_string.utf8();
80 m_parsed = parsed;
81 m_isValid = isValid;
82 } 75 }
83 76
84 const WebCString& spec() const 77 const WebString& string() const
85 { 78 {
86 return m_spec; 79 return m_string;
87 } 80 }
88 81
89 const url_parse::Parsed& parsed() const 82 const url_parse::Parsed& parsed() const
90 { 83 {
91 return m_parsed; 84 return m_parsed;
92 } 85 }
93 86
94 bool isValid() const 87 bool isValid() const
95 { 88 {
96 return m_isValid; 89 return m_isValid;
97 } 90 }
98 91
99 bool isEmpty() const 92 bool isEmpty() const
100 { 93 {
101 return m_spec.isEmpty(); 94 return m_string.isEmpty();
102 } 95 }
103 96
104 bool isNull() const 97 bool isNull() const
105 { 98 {
106 return m_spec.isEmpty(); 99 return m_string.isEmpty();
107 } 100 }
108 101
109 #if WEBKIT_IMPLEMENTATION 102 #if WEBKIT_IMPLEMENTATION
110 WebURL(const WebCore::KURL&); 103 WebURL(const WebCore::KURL&);
111 WebURL& operator=(const WebCore::KURL&); 104 WebURL& operator=(const WebCore::KURL&);
112 operator WebCore::KURL() const; 105 operator WebCore::KURL() const;
113 #else 106 #else
114 WebURL(const GURL& g) 107 WebURL(const GURL& url)
115 : m_spec(g.possibly_invalid_spec()) 108 : m_string(WebString::fromUTF8(url.possibly_invalid_spec()))
116 , m_parsed(g.parsed_for_possibly_invalid_spec()) 109 , m_parsed(url.parsed_for_possibly_invalid_spec())
117 , m_isValid(g.is_valid()) 110 , m_isValid(url.is_valid())
118 { 111 {
119 } 112 }
120 113
121 WebURL& operator=(const GURL& g) 114 WebURL& operator=(const GURL& url)
122 { 115 {
123 m_spec = g.possibly_invalid_spec(); 116 m_string = WebString::fromUTF8(url.possibly_invalid_spec());
124 m_parsed = g.parsed_for_possibly_invalid_spec(); 117 m_parsed = url.parsed_for_possibly_invalid_spec();
125 m_isValid = g.is_valid(); 118 m_isValid = url.is_valid();
126 return *this; 119 return *this;
127 } 120 }
128 121
129 operator GURL() const 122 operator GURL() const
130 { 123 {
131 return isNull() ? GURL() : GURL(m_spec.data(), m_spec.length(), m_parsed , m_isValid); 124 return isNull() ? GURL() : GURL(m_string.toUTF8String(), m_parsed, m_isV alid);
132 } 125 }
133 #endif 126 #endif
134 127
135 private: 128 private:
136 WebCString m_spec; // UTF-8 encoded 129 WebString m_string;
137 url_parse::Parsed m_parsed; 130 url_parse::Parsed m_parsed;
138 bool m_isValid; 131 bool m_isValid;
139 }; 132 };
140 133
141 inline bool operator<(const WebURL& a, const WebURL& b)
142 {
143 return a.spec() < b.spec();
144 }
145
146 inline bool operator==(const WebURL& a, const WebURL& b) 134 inline bool operator==(const WebURL& a, const WebURL& b)
147 { 135 {
148 return !a.spec().compare(b.spec()); 136 return a.string().equals(b.string());
149 } 137 }
150 138
151 inline bool operator!=(const WebURL& a, const WebURL& b) 139 inline bool operator!=(const WebURL& a, const WebURL& b)
152 { 140 {
153 return !(a == b); 141 return !(a == b);
154 } 142 }
155 143
156 } // namespace WebKit 144 } // namespace WebKit
157 145
158 #endif 146 #endif
OLDNEW
« public/platform/WebString.h ('K') | « public/platform/WebString.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698