"${CMAKE_SOURCE_DIR}/contrib/frozen/include"
"${CMAKE_SOURCE_DIR}/contrib/fmt/include"
"${CMAKE_SOURCE_DIR}/contrib/doctest"
- "${CMAKE_BINARY_DIR}/contrib/fu2/include"
+ "${CMAKE_SOURCE_DIR}/contrib/fu2/include"
"${CMAKE_BINARY_DIR}/src" #Stored in the binary dir
"${CMAKE_BINARY_DIR}/src/libcryptobox")
{
css_parser parser(pool);
- /*
- * We use shared ptr here to avoid std::function limitation around
- * unique_ptr due to copyable of std::function
- * Hence, to elongate consumed_blocks lifetime we need to copy them
- * inside lambda.
- */
- std::shared_ptr<css_consumed_block> consumed_blocks = parser.consume_css_blocks(st);
+ auto &&consumed_blocks = parser.consume_css_blocks(st);
const auto &rules = consumed_blocks->get_blocks_or_empty();
auto rules_it = rules.begin();
auto cur = children.begin();
auto last = children.end();
- return [cur, consumed_blocks, last](void) mutable -> const css_consumed_block & {
+ /*
+ * We use move only wrapper to state the fact that the cosumed blocks
+ * are moved into the closure, not copied.
+ * It prevents us from thinking about copies of the blocks and
+ * functors.
+ * Mutable lambda is required to copy iterators inside of the closure,
+ * as, again, it is C++ where lifetime of the objects must be explicitly
+ * transferred. On the other hand, we could move all stuff inside and remove
+ * mutable.
+ */
+ return [cur, consumed_blocks = std::move(consumed_blocks), last](void) mutable
+ -> const css_consumed_block & {
if (cur != last) {
const auto &ret = (*cur);
#include <memory>
#include <string>
+#include "function2/function2.hpp"
#include "css_tokeniser.hxx"
#include "parse_error.hxx"
#include "contrib/expected/expected.hpp"
extern const css_consumed_block css_parser_eof_block;
-using blocks_gen_functor = std::function<const css_consumed_block &(void)>;
+using blocks_gen_functor = fu2::unique_function<const css_consumed_block &(void)>;
class css_style_sheet;
auto parse_css(rspamd_mempool_t *pool, const std::string_view &st) ->
}
auto process_declaration_tokens(rspamd_mempool_t *pool,
- const blocks_gen_functor &next_block_functor)
+ blocks_gen_functor &&next_block_functor)
-> css_declarations_block_ptr
{
css_declarations_block_ptr ret;
using css_declarations_block_ptr = std::shared_ptr<css_declarations_block>;
auto process_declaration_tokens(rspamd_mempool_t *pool,
- const blocks_gen_functor &next_token_functor)
+ blocks_gen_functor &&next_token_functor)
-> css_declarations_block_ptr;
}
namespace rspamd::css {
auto process_selector_tokens(rspamd_mempool_t *pool,
- const blocks_gen_functor &next_token_functor)
+ blocks_gen_functor &&next_token_functor)
-> selectors_vec
{
selectors_vec ret;
#include <string>
#include <optional>
#include <vector>
-#include <functional>
#include <memory>
+#include "function2/function2.hpp"
#include "parse_error.hxx"
#include "css_parser.hxx"
#include "html_tags.h"
* Consume selectors token and split them to the list of selectors
*/
auto process_selector_tokens(rspamd_mempool_t *pool,
- const blocks_gen_functor &next_token_functor)
+ blocks_gen_functor &&next_token_functor)
-> selectors_vec;
}