summaryrefslogtreecommitdiffstats
path: root/dom/fetch/InternalHeaders.cpp
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-04-15 11:51:43 +0200
committerwolfbeast <mcwerewolf@gmail.com>2018-04-15 11:51:43 +0200
commitbdd013826b8acbdef0ae43233d7a6a32e1161966 (patch)
tree83904a8337bfb28e1fa059afe5bc088a8b454688 /dom/fetch/InternalHeaders.cpp
parentfca67bb95d4cda5046365e124e79ec583c336697 (diff)
parent8a95c03dcd2a7f2c6d64b6ee917f6cb363e9ca60 (diff)
downloadUXP-bdd013826b8acbdef0ae43233d7a6a32e1161966.tar
UXP-bdd013826b8acbdef0ae43233d7a6a32e1161966.tar.gz
UXP-bdd013826b8acbdef0ae43233d7a6a32e1161966.tar.lz
UXP-bdd013826b8acbdef0ae43233d7a6a32e1161966.tar.xz
UXP-bdd013826b8acbdef0ae43233d7a6a32e1161966.zip
Merge branch 'master' of https://github.com/MoonchildProductions/UXP
Diffstat (limited to 'dom/fetch/InternalHeaders.cpp')
-rw-r--r--dom/fetch/InternalHeaders.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/dom/fetch/InternalHeaders.cpp b/dom/fetch/InternalHeaders.cpp
index e81863173..11585615e 100644
--- a/dom/fetch/InternalHeaders.cpp
+++ b/dom/fetch/InternalHeaders.cpp
@@ -21,12 +21,14 @@ InternalHeaders::InternalHeaders(const nsTArray<Entry>&& aHeaders,
HeadersGuardEnum aGuard)
: mGuard(aGuard)
, mList(aHeaders)
+ , mListDirty(true)
{
}
InternalHeaders::InternalHeaders(const nsTArray<HeadersEntry>& aHeadersEntryList,
HeadersGuardEnum aGuard)
: mGuard(aGuard)
+ , mListDirty(true)
{
for (const HeadersEntry& headersEntry : aHeadersEntryList) {
mList.AppendElement(Entry(headersEntry.name(), headersEntry.value()));
@@ -56,6 +58,8 @@ InternalHeaders::Append(const nsACString& aName, const nsACString& aValue,
return;
}
+ SetListDirty();
+
mList.AppendElement(Entry(lowerName, aValue));
}
@@ -69,6 +73,8 @@ InternalHeaders::Delete(const nsACString& aName, ErrorResult& aRv)
return;
}
+ SetListDirty();
+
// remove in reverse order to minimize copying
for (int32_t i = mList.Length() - 1; i >= 0; --i) {
if (lowerName == mList[i].mName) {
@@ -155,6 +161,8 @@ InternalHeaders::Set(const nsACString& aName, const nsACString& aValue, ErrorRes
return;
}
+ SetListDirty();
+
int32_t firstIndex = INT32_MAX;
// remove in reverse order to minimize copying
@@ -177,6 +185,7 @@ InternalHeaders::Set(const nsACString& aName, const nsACString& aValue, ErrorRes
void
InternalHeaders::Clear()
{
+ SetListDirty();
mList.Clear();
}
@@ -419,5 +428,54 @@ InternalHeaders::GetUnsafeHeaders(nsTArray<nsCString>& aNames) const
}
}
+void
+InternalHeaders::MaybeSortList()
+{
+ class Comparator {
+ public:
+ bool Equals(const Entry& aA, const Entry& aB) const
+ {
+ return aA.mName == aB.mName;
+ }
+
+ bool LessThan(const Entry& aA, const Entry& aB) const
+ {
+ return aA.mName < aB.mName;
+ }
+ };
+
+ if (!mListDirty) {
+ return;
+ }
+
+ mListDirty = false;
+
+ Comparator comparator;
+
+ mSortedList.Clear();
+ for (const Entry& entry : mList) {
+ bool found = false;
+ for (Entry& sortedEntry : mSortedList) {
+ if (sortedEntry.mName == entry.mName) {
+ sortedEntry.mValue += ", ";
+ sortedEntry.mValue += entry.mValue;
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ mSortedList.InsertElementSorted(entry, comparator);
+ }
+ }
+}
+
+void
+InternalHeaders::SetListDirty()
+{
+ mSortedList.Clear();
+ mListDirty = true;
+}
+
} // namespace dom
} // namespace mozilla