Remove CFX_CSSSelector::set_next().
Set |CFX_CSSSelector::next_| in the ctor.
Change-Id: I37601678373cd6b07484f28afa48164e5986bb30
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/70732
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/css/cfx_cssselector.cpp b/core/fxcrt/css/cfx_cssselector.cpp
index 9f3eeb5..53f00b0 100644
--- a/core/fxcrt/css/cfx_cssselector.cpp
+++ b/core/fxcrt/css/cfx_cssselector.cpp
@@ -25,9 +25,12 @@
} // namespace
-CFX_CSSSelector::CFX_CSSSelector(const wchar_t* psz, int32_t iLen)
+CFX_CSSSelector::CFX_CSSSelector(const wchar_t* psz,
+ int32_t iLen,
+ std::unique_ptr<CFX_CSSSelector> next)
: name_hash_(
- FX_HashCode_GetW(WideStringView(psz, iLen), /*bIgnoreCase=*/true)) {}
+ FX_HashCode_GetW(WideStringView(psz, iLen), /*bIgnoreCase=*/true)),
+ next_(std::move(next)) {}
CFX_CSSSelector::~CFX_CSSSelector() = default;
@@ -52,12 +55,11 @@
for (psz = pStart; psz < pEnd;) {
wchar_t wch = *psz;
if ((isascii(wch) && isalpha(wch)) || wch == '*') {
- int32_t iNameLen = wch == '*' ? 1 : GetCSSNameLen(psz, pEnd);
- auto new_head = std::make_unique<CFX_CSSSelector>(psz, iNameLen);
- if (head) {
+ if (head)
head->set_is_descendant();
- new_head->set_next(std::move(head));
- }
+ int32_t iNameLen = wch == '*' ? 1 : GetCSSNameLen(psz, pEnd);
+ auto new_head =
+ std::make_unique<CFX_CSSSelector>(psz, iNameLen, std::move(head));
head = std::move(new_head);
psz += iNameLen;
} else if (wch == ' ') {
diff --git a/core/fxcrt/css/cfx_cssselector.h b/core/fxcrt/css/cfx_cssselector.h
index 5839779..91778ab 100644
--- a/core/fxcrt/css/cfx_cssselector.h
+++ b/core/fxcrt/css/cfx_cssselector.h
@@ -8,7 +8,6 @@
#define CORE_FXCRT_CSS_CFX_CSSSELECTOR_H_
#include <memory>
-#include <utility>
#include "core/fxcrt/fx_string.h"
@@ -16,23 +15,21 @@
public:
static std::unique_ptr<CFX_CSSSelector> FromString(WideStringView str);
- CFX_CSSSelector(const wchar_t* psz, int32_t iLen);
+ CFX_CSSSelector(const wchar_t* psz,
+ int32_t iLen,
+ std::unique_ptr<CFX_CSSSelector> next);
~CFX_CSSSelector();
bool is_descendant() const { return is_descendant_; }
uint32_t name_hash() const { return name_hash_; }
const CFX_CSSSelector* next_selector() const { return next_.get(); }
- void set_next(std::unique_ptr<CFX_CSSSelector> pNext) {
- next_ = std::move(pNext);
- }
-
private:
void set_is_descendant() { is_descendant_ = true; }
bool is_descendant_ = false;
const uint32_t name_hash_;
- std::unique_ptr<CFX_CSSSelector> next_;
+ const std::unique_ptr<CFX_CSSSelector> next_;
};
#endif // CORE_FXCRT_CSS_CFX_CSSSELECTOR_H_