Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: compiled/String.h

Issue 29722755: Issue 6378 - [emscripten] Make DependentString constexpr
Patch Set: Added missing '*'. Created March 19, 2018, 1:39 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/compiled/String.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/String.h
diff --git a/compiled/String.h b/compiled/String.h
index 70086f847b913460c906d285ff85c9f8013f8a67..5ee0d39a13bc4089a4d1751f44e3eb5bce88a8f6 100644
--- a/compiled/String.h
+++ b/compiled/String.h
@@ -76,14 +76,12 @@ protected:
value_type* mBuf;
size_type mLen;
- explicit String(value_type* buf, size_type len, size_type flags)
+ constexpr explicit String(value_type* buf, size_type len, size_type flags)
: mBuf(buf), mLen((len & LENGTH_MASK) | flags)
{
}
- ~String()
- {
- }
+ ~String() = default;
void reset(value_type* buf, size_type len, size_type flags)
{
@@ -92,17 +90,17 @@ protected:
}
public:
- size_type length() const
+ constexpr size_type length() const
{
return mLen & LENGTH_MASK;
}
- bool empty() const
+ constexpr bool empty() const
{
return !(mLen & LENGTH_MASK);
}
- const value_type* data() const
+ constexpr const value_type* data() const
{
return mBuf;
}
@@ -113,7 +111,7 @@ public:
return mBuf;
}
- const value_type& operator[](size_type pos) const
+ constexpr const value_type& operator[](size_type pos) const
{
return mBuf[pos];
}
@@ -124,12 +122,12 @@ public:
return mBuf[pos];
}
- bool is_writable() const
+ constexpr bool is_writable() const
{
return (mLen & FLAGS_MASK) == READ_WRITE;
}
- bool equals(const String& other) const
+ constexpr bool equals(const String& other) const
{
if (length() != other.length())
return false;
@@ -137,17 +135,17 @@ public:
return std::memcmp(mBuf, other.mBuf, sizeof(value_type) * length()) == 0;
}
- bool operator==(const String& other) const
+ constexpr bool operator==(const String& other) const
{
return equals(other);
}
- bool operator!=(const String& other) const
+ constexpr bool operator!=(const String& other) const
{
return !equals(other);
}
- size_type find(value_type c, size_type pos = 0) const
+ constexpr size_type find(value_type c, size_type pos = 0) const
{
for (size_type i = pos; i < length(); ++i)
if (mBuf[i] == c)
@@ -155,12 +153,12 @@ public:
return npos;
}
- size_type find(const String& str, size_type pos = 0) const
+ constexpr size_type find(const String& str, size_type pos = 0) const
{
return find(str.mBuf, pos, str.length());
}
- size_type find(const value_type* str, size_type pos, size_type count) const
+ constexpr size_type find(const value_type* str, size_type pos, size_type count) const
{
if (pos > LENGTH_MASK || pos + count > length())
return npos;
@@ -180,7 +178,7 @@ public:
return npos;
}
- size_type rfind(value_type c, size_type pos = npos) const
+ constexpr size_type rfind(value_type c, size_type pos = npos) const
{
if (length() == 0)
return npos;
@@ -194,12 +192,12 @@ public:
return npos;
}
- bool is_invalid() const
+ constexpr bool is_invalid() const
{
return (mLen & FLAGS_MASK) == INVALID;
}
- bool is_deleted() const
+ constexpr bool is_deleted() const
{
return (mLen & FLAGS_MASK) == DELETED;
}
@@ -245,17 +243,23 @@ inline std::ostream& operator<<(std::ostream& os, const String& str)
class DependentString : public String
{
public:
- explicit DependentString()
+ constexpr explicit DependentString()
: String(nullptr, 0, INVALID)
{
}
+ template <int N1>
+ constexpr explicit DependentString(const value_type (&buf)[N1])
+ : String(const_cast<value_type*>(buf), N1 - 1, READ_ONLY)
+ {
+ }
+
explicit DependentString(value_type* buf, size_type len)
: String(buf, len, READ_WRITE)
{
}
- explicit DependentString(const value_type* buf, size_type len)
+ constexpr explicit DependentString(const value_type* buf, size_type len)
: String(const_cast<value_type*>(buf), len, READ_ONLY)
{
}
@@ -313,7 +317,7 @@ inline std::ostream& operator<<(std::ostream& os, const DependentString& str)
}
#endif
-inline DependentString operator "" _str(const String::value_type* str,
+constexpr DependentString operator "" _str(const String::value_type* str,
String::size_type len)
{
return DependentString(str, len);
« no previous file with comments | « no previous file | test/compiled/String.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld