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

Side by Side Diff: Source/wtf/text/WTFString.h

Issue 21274008: Remove ASCIILiteral optimization from StringImpl (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 4 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
« no previous file with comments | « Source/wtf/text/StringImpl.cpp ('k') | Source/wtf/text/WTFString.cpp » ('j') | 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 * (C) 1999 Lars Knoll (knoll@kde.org) 2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // FIXME: Like the strict functions above, these give false for "ok" when there is trailing garbage. 67 // FIXME: Like the strict functions above, these give false for "ok" when there is trailing garbage.
68 // Like the non-strict functions above, these return the value when there is tra iling garbage. 68 // Like the non-strict functions above, these return the value when there is tra iling garbage.
69 // It would be better if these were more consistent with the above functions ins tead. 69 // It would be better if these were more consistent with the above functions ins tead.
70 WTF_EXPORT double charactersToDouble(const LChar*, size_t, bool* ok = 0); 70 WTF_EXPORT double charactersToDouble(const LChar*, size_t, bool* ok = 0);
71 WTF_EXPORT double charactersToDouble(const UChar*, size_t, bool* ok = 0); 71 WTF_EXPORT double charactersToDouble(const UChar*, size_t, bool* ok = 0);
72 WTF_EXPORT float charactersToFloat(const LChar*, size_t, bool* ok = 0); 72 WTF_EXPORT float charactersToFloat(const LChar*, size_t, bool* ok = 0);
73 WTF_EXPORT float charactersToFloat(const UChar*, size_t, bool* ok = 0); 73 WTF_EXPORT float charactersToFloat(const UChar*, size_t, bool* ok = 0);
74 WTF_EXPORT float charactersToFloat(const LChar*, size_t, size_t& parsedLength); 74 WTF_EXPORT float charactersToFloat(const LChar*, size_t, size_t& parsedLength);
75 WTF_EXPORT float charactersToFloat(const UChar*, size_t, size_t& parsedLength); 75 WTF_EXPORT float charactersToFloat(const UChar*, size_t, size_t& parsedLength);
76 76
77 class ASCIILiteral;
78
79 enum TrailingZerosTruncatingPolicy { 77 enum TrailingZerosTruncatingPolicy {
80 KeepTrailingZeros, 78 KeepTrailingZeros,
81 TruncateTrailingZeros 79 TruncateTrailingZeros
82 }; 80 };
83 81
84 template<bool isSpecialCharacter(UChar), typename CharacterType> 82 template<bool isSpecialCharacter(UChar), typename CharacterType>
85 bool isAllSpecialCharacters(const CharacterType*, size_t); 83 bool isAllSpecialCharacters(const CharacterType*, size_t);
86 84
85 // FIXME: Remove this class once all callers are gone.
86 class ASCIILiteral {
87 public:
88 explicit ASCIILiteral(const char* characters) : m_characters(characters) { }
89 operator const char*() { return m_characters; }
90
91 private:
92 const char* m_characters;
93 };
94
87 class WTF_EXPORT String { 95 class WTF_EXPORT String {
88 public: 96 public:
89 // Construct a null string, distinguishable from an empty string. 97 // Construct a null string, distinguishable from an empty string.
90 String() { } 98 String() { }
91 99
92 // Construct a string with UTF-16 data. 100 // Construct a string with UTF-16 data.
93 String(const UChar* characters, unsigned length); 101 String(const UChar* characters, unsigned length);
94 102
95 // Construct a string by copying the contents of a vector. 103 // Construct a string by copying the contents of a vector.
96 // This method will never create a null string. Vectors with size() == 0 104 // This method will never create a null string. Vectors with size() == 0
(...skipping 14 matching lines...) Expand all
111 119
112 // Construct a string with latin1 data, from a null-terminated source. 120 // Construct a string with latin1 data, from a null-terminated source.
113 String(const LChar* characters); 121 String(const LChar* characters);
114 String(const char* characters); 122 String(const char* characters);
115 123
116 // Construct a string referencing an existing StringImpl. 124 // Construct a string referencing an existing StringImpl.
117 String(StringImpl* impl) : m_impl(impl) { } 125 String(StringImpl* impl) : m_impl(impl) { }
118 String(PassRefPtr<StringImpl> impl) : m_impl(impl) { } 126 String(PassRefPtr<StringImpl> impl) : m_impl(impl) { }
119 String(RefPtr<StringImpl> impl) : m_impl(impl) { } 127 String(RefPtr<StringImpl> impl) : m_impl(impl) { }
120 128
121 // Construct a string from a constant string literal. 129 // FIXME: Remove this API once all callers are gone.
122 String(ASCIILiteral characters);
123
124 // Construct a string from a constant string literal.
125 // This constructor is the "big" version, as it put the length in the functi on call and generate bigger code.
126 enum ConstructFromLiteralTag { ConstructFromLiteral }; 130 enum ConstructFromLiteralTag { ConstructFromLiteral };
127 template<unsigned charactersCount> 131 String(const char* characters, ConstructFromLiteralTag) : m_impl(StringImpl: :create(reinterpret_cast<const LChar*>(characters))) { }
128 String(const char (&characters)[charactersCount], ConstructFromLiteralTag) : m_impl(StringImpl::createFromLiteral<charactersCount>(characters)) { } 132 String(ASCIILiteral literal) : m_impl(StringImpl::create(reinterpret_cast<co nst LChar*>(static_cast<const char*>(literal)))) { }
129 133
130 #if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES) 134 #if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
131 // We have to declare the copy constructor and copy assignment operator as w ell, otherwise 135 // We have to declare the copy constructor and copy assignment operator as w ell, otherwise
132 // they'll be implicitly deleted by adding the move constructor and move ass ignment operator. 136 // they'll be implicitly deleted by adding the move constructor and move ass ignment operator.
133 String(const String& other) : m_impl(other.m_impl) { } 137 String(const String& other) : m_impl(other.m_impl) { }
134 String(String&& other) : m_impl(other.m_impl.release()) { } 138 String(String&& other) : m_impl(other.m_impl.release()) { }
135 String& operator=(const String& other) { m_impl = other.m_impl; return *this ; } 139 String& operator=(const String& other) { m_impl = other.m_impl; return *this ; }
136 String& operator=(String&& other) { m_impl = other.m_impl.release(); return *this; } 140 String& operator=(String&& other) { m_impl = other.m_impl.release(); return *this; }
137 #endif 141 #endif
138 142
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 } 687 }
684 688
685 // StringHash is the default hash for String 689 // StringHash is the default hash for String
686 template<typename T> struct DefaultHash; 690 template<typename T> struct DefaultHash;
687 template<> struct DefaultHash<String> { 691 template<> struct DefaultHash<String> {
688 typedef StringHash Hash; 692 typedef StringHash Hash;
689 }; 693 };
690 694
691 template <> struct VectorTraits<String> : SimpleClassVectorTraits { }; 695 template <> struct VectorTraits<String> : SimpleClassVectorTraits { };
692 696
693 class ASCIILiteral {
694 public:
695 explicit ASCIILiteral(const char* characters) : m_characters(characters) { }
696 operator const char*() { return m_characters; }
697
698 private:
699 const char* m_characters;
700 };
701
702 // Shared global empty string. 697 // Shared global empty string.
703 WTF_EXPORT const String& emptyString(); 698 WTF_EXPORT const String& emptyString();
704 699
705 } 700 }
706 701
707 using WTF::CString; 702 using WTF::CString;
708 using WTF::KeepTrailingZeros; 703 using WTF::KeepTrailingZeros;
709 using WTF::String; 704 using WTF::String;
710 using WTF::emptyString; 705 using WTF::emptyString;
711 using WTF::append; 706 using WTF::append;
(...skipping 14 matching lines...) Expand all
726 using WTF::equal; 721 using WTF::equal;
727 using WTF::equalIgnoringCase; 722 using WTF::equalIgnoringCase;
728 using WTF::find; 723 using WTF::find;
729 using WTF::isAllSpecialCharacters; 724 using WTF::isAllSpecialCharacters;
730 using WTF::isSpaceOrNewline; 725 using WTF::isSpaceOrNewline;
731 using WTF::reverseFind; 726 using WTF::reverseFind;
732 using WTF::ASCIILiteral; 727 using WTF::ASCIILiteral;
733 728
734 #include "wtf/text/AtomicString.h" 729 #include "wtf/text/AtomicString.h"
735 #endif 730 #endif
OLDNEW
« no previous file with comments | « Source/wtf/text/StringImpl.cpp ('k') | Source/wtf/text/WTFString.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698