summaryrefslogtreecommitdiffstats
path: root/parser/html/nsHtml5String.h
diff options
context:
space:
mode:
authorwin7-7 <win7-7@users.noreply.github.com>2019-07-05 21:58:21 +0300
committerwin7-7 <win7-7@users.noreply.github.com>2019-07-05 21:58:21 +0300
commit7c5a0db237c7a43136ee3cdc6cfb0663778d9e2c (patch)
tree9cd5a806763b73bed3fef3d599f32b525f4c0d7a /parser/html/nsHtml5String.h
parent0e54a032624b4ce23a959454047bfd504a734cc0 (diff)
downloadUXP-7c5a0db237c7a43136ee3cdc6cfb0663778d9e2c.tar
UXP-7c5a0db237c7a43136ee3cdc6cfb0663778d9e2c.tar.gz
UXP-7c5a0db237c7a43136ee3cdc6cfb0663778d9e2c.tar.lz
UXP-7c5a0db237c7a43136ee3cdc6cfb0663778d9e2c.tar.xz
UXP-7c5a0db237c7a43136ee3cdc6cfb0663778d9e2c.zip
Introduce a new non-heap-allocated type for holding nsStringBuffer* in the HTML parser.
An innerHTML setter profile shows about 10% of the time being spent under nsHtml5HtmlAttributes::clear, mostly deleting nsStrings.
Diffstat (limited to 'parser/html/nsHtml5String.h')
-rw-r--r--parser/html/nsHtml5String.h95
1 files changed, 95 insertions, 0 deletions
diff --git a/parser/html/nsHtml5String.h b/parser/html/nsHtml5String.h
new file mode 100644
index 000000000..191bf6be8
--- /dev/null
+++ b/parser/html/nsHtml5String.h
@@ -0,0 +1,95 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nsHtml5String_h
+#define nsHtml5String_h
+
+#include "nsString.h"
+
+class nsHtml5TreeBuilder;
+
+/**
+ * A pass-by-value type that combines an unsafe `nsStringBuffer*` with its
+ * logical length (`uint32_t`). (`nsStringBuffer` knows its capacity but not
+ * its logical length, i.e. how much of the capacity is in use.)
+ *
+ * Holding or passing this type is as unsafe as holding or passing
+ * `nsStringBuffer*`.
+ *
+ * Empty strings and null strings are distinct. Since an empty nsString does
+ * not have a an `nsStringBuffer`, both empty and null `nsHtml5String` have
+ * `nullptr` as `mBuffer`. If `mBuffer` is `nullptr`, the empty case is marked
+ * with `mLength` being zero and the null case with `mLength` being non-zero.
+ */
+class nsHtml5String final
+{
+public:
+ /**
+ * Default constructor.
+ */
+ inline nsHtml5String()
+ : nsHtml5String(nullptr)
+ {
+ }
+
+ /**
+ * Constructor from nullptr.
+ */
+ inline MOZ_IMPLICIT nsHtml5String(decltype(nullptr))
+ : mBuffer(nullptr)
+ , mLength(UINT32_MAX)
+ {
+ }
+
+ inline uint32_t Length() const { return mBuffer ? mLength : 0; }
+
+ /**
+ * False iff the string is logically null
+ */
+ inline MOZ_IMPLICIT operator bool() const { return !(!mBuffer && mLength); }
+
+ void ToString(nsAString& aString);
+
+ void CopyToBuffer(char16_t* aBuffer);
+
+ bool LowerCaseEqualsASCII(const char* aLowerCaseLiteral);
+
+ bool EqualsASCII(const char* aLiteral);
+
+ bool LowerCaseStartsWithASCII(const char* aLowerCaseLiteral);
+
+ bool Equals(nsHtml5String aOther);
+
+ nsHtml5String Clone();
+
+ void Release();
+
+ static nsHtml5String FromBuffer(char16_t* aBuffer,
+ int32_t aLength,
+ nsHtml5TreeBuilder* aTreeBuilder);
+
+ static nsHtml5String FromLiteral(const char* aLiteral);
+
+ static nsHtml5String FromString(const nsAString& aString);
+
+ static nsHtml5String EmptyString();
+
+private:
+ /**
+ * Constructor from raw parts.
+ */
+ nsHtml5String(already_AddRefed<nsStringBuffer> aBuffer, uint32_t aLength);
+
+ /**
+ * nullptr if the string is logically null or logically empty
+ */
+ nsStringBuffer* mBuffer;
+
+ /**
+ * The length of the string. non-zero if the string is logically null.
+ */
+ uint32_t mLength;
+};
+
+#endif // nsHtml5String_h \ No newline at end of file