/*
* This source file is part of RmlUi, the HTML/CSS Interface Middleware
*
* For the latest information, see http://github.com/mikke89/RmlUi
*
* Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
* Copyright (c) 2019 The RmlUi Team, and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
#include "../Common/TestsShell.h"
#include
#include
#include
#include
#include
#include
using namespace ankerl;
using namespace Rml;
static constexpr const char* document_rml_template = R"(
Benchmark Sample
)";
static int GetNumDescendentElements(Element* element)
{
const int num_children = element->GetNumChildren(true);
int result = num_children;
for (int i = 0; i < num_children; i++)
{
result += GetNumDescendentElements(element->GetChild(i));
}
return result;
}
static constexpr int num_rule_iterations = 10;
enum SelectorFlags {
NO_SELECTOR,
TAG = 1 << 0,
ID = 1 << 1,
CLASS = 1 << 2,
PSEUDO_CLASS = 1 << 3,
ATTRIBUTE = 1 << 4,
NUM_COMBINATIONS = 1 << 5,
};
static String GenerateRCSS(SelectorFlags selectors, const String& complex_selector, String& out_rule_name)
{
static_assert('a' < 'z' && 'a' + 25 == 'z', "Assumes ASCII characters");
auto GenerateRule = [=](const String& name) {
String rule;
if (!complex_selector.empty())
{
rule = complex_selector;
}
else if (selectors == NO_SELECTOR || name.empty())
{
rule += '*';
}
else
{
if (selectors & TAG)
{
if (selectors == TAG)
rule += name;
else
rule += "div";
}
if (selectors & ID)
rule += '#' + name;
if (selectors & CLASS)
rule += '.' + name;
if (selectors & PSEUDO_CLASS)
rule += ':' + name;
if (selectors & ATTRIBUTE)
rule += '[' + name + ']';
}
return rule;
};
out_rule_name = GenerateRule("a");
String result;
for (int i = 0; i < num_rule_iterations; i++)
{
for (char c = 'a'; c <= 'z'; c++)
{
const String name(i, c);
result += GenerateRule(name);
// Set a property that does not require a layout change
result += CreateString(64, " { scrollbar-margin: %dpx; }\n", int(c - 'a') + 1);
#if 1
// This conditions ensures that only a single version of the complex selector is included. This can be disabled to test how well the rules
// are de-duplicated, since then a lot more selectors will be tested per update call. Rules that contain sub-selectors are currently not
// de-duplicated, such as :not().
if (!complex_selector.empty())
return result;
#endif
}
}
return result;
}
static String GenerateRml(const int num_rows)
{
static nanobench::Rng rng;
Rml::String rml;
rml.reserve(1000 * num_rows);
for (int i = 0; i < num_rows; i++)
{
int index = rng() % 1000;
int route = rng() % 50;
int max = (rng() % 40) + 10;
int value = rng() % max;
String class_name_a = char('a' + char(rng() % 26)) + ToString(rng() % num_rule_iterations);
String class_name_b = char('a' + char(rng() % 26)) + ToString(rng() % num_rule_iterations);
Rml::String rml_row = Rml::CreateString(1000, R"(