diff options
author | janekptacijarabaci <janekptacijarabaci@seznam.cz> | 2018-04-14 22:18:47 +0200 |
---|---|---|
committer | janekptacijarabaci <janekptacijarabaci@seznam.cz> | 2018-04-14 22:18:47 +0200 |
commit | 9ee567082c6bdf949f6c02a7e6c2e8b7bfef6590 (patch) | |
tree | 8974811cc99df1ea2658fbdf9ca8c5f69767077d /dom/fetch/InternalHeaders.h | |
parent | c73c73b7978d7fc12e0dc07bb7c8f3babd497b8c (diff) | |
download | UXP-9ee567082c6bdf949f6c02a7e6c2e8b7bfef6590.tar UXP-9ee567082c6bdf949f6c02a7e6c2e8b7bfef6590.tar.gz UXP-9ee567082c6bdf949f6c02a7e6c2e8b7bfef6590.tar.lz UXP-9ee567082c6bdf949f6c02a7e6c2e8b7bfef6590.tar.xz UXP-9ee567082c6bdf949f6c02a7e6c2e8b7bfef6590.zip |
moebius#140: Fix: Fetch - headers should sort and combine
https://github.com/MoonchildProductions/moebius/pull/140
Diffstat (limited to 'dom/fetch/InternalHeaders.h')
-rw-r--r-- | dom/fetch/InternalHeaders.h | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/dom/fetch/InternalHeaders.h b/dom/fetch/InternalHeaders.h index e47066669..9a6d6dae7 100644 --- a/dom/fetch/InternalHeaders.h +++ b/dom/fetch/InternalHeaders.h @@ -45,14 +45,23 @@ private: HeadersGuardEnum mGuard; nsTArray<Entry> mList; + nsTArray<Entry> mSortedList; + + // This boolean is set to true at any writing operation to mList. It's set to + // false when mSortedList is regenerated. This happens when the header is + // iterated. + bool mListDirty; + public: explicit InternalHeaders(HeadersGuardEnum aGuard = HeadersGuardEnum::None) : mGuard(aGuard) + , mListDirty(false) { } explicit InternalHeaders(const InternalHeaders& aOther) : mGuard(HeadersGuardEnum::None) + , mListDirty(true) { ErrorResult result; Fill(aOther, result); @@ -79,19 +88,22 @@ public: bool Has(const nsACString& aName, ErrorResult& aRv) const; void Set(const nsACString& aName, const nsACString& aValue, ErrorResult& aRv); - uint32_t GetIterableLength() const + uint32_t GetIterableLength() { - return mList.Length(); + MaybeSortList(); + return mSortedList.Length(); } - const NS_ConvertASCIItoUTF16 GetKeyAtIndex(unsigned aIndex) const + const NS_ConvertASCIItoUTF16 GetKeyAtIndex(unsigned aIndex) { - MOZ_ASSERT(aIndex < mList.Length()); - return NS_ConvertASCIItoUTF16(mList[aIndex].mName); + MaybeSortList(); + MOZ_ASSERT(aIndex < mSortedList.Length()); + return NS_ConvertASCIItoUTF16(mSortedList[aIndex].mName); } - const NS_ConvertASCIItoUTF16 GetValueAtIndex(unsigned aIndex) const + const NS_ConvertASCIItoUTF16 GetValueAtIndex(unsigned aIndex) { - MOZ_ASSERT(aIndex < mList.Length()); - return NS_ConvertASCIItoUTF16(mList[aIndex].mValue); + MaybeSortList(); + MOZ_ASSERT(aIndex < mSortedList.Length()); + return NS_ConvertASCIItoUTF16(mSortedList[aIndex].mValue); } void Clear(); @@ -152,6 +164,9 @@ private: const nsACString& aValue); static bool IsRevalidationHeader(const nsACString& aName); + + void MaybeSortList(); + void SetListDirty(); }; } // namespace dom |