Skip to content

Commit

Permalink
Commit unrolled range-based for loops
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed May 22, 2017
1 parent 59e6ae0 commit 47c834b
Show file tree
Hide file tree
Showing 22 changed files with 109 additions and 115 deletions.
38 changes: 18 additions & 20 deletions src/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Sass {
bool Selector_List::find ( bool (*f)(AST_Node_Obj) )
{
// check children first
for (Complex_Selector_Obj sel : elements()) {
for (auto __sel = (elements()).begin(); __sel != (elements()).end(); ++__sel) { Complex_Selector_Obj sel = *(__sel);
if (sel->find(f)) return true;
}
// execute last
Expand All @@ -42,7 +42,7 @@ namespace Sass {
bool Compound_Selector::find ( bool (*f)(AST_Node_Obj) )
{
// check children first
for (Simple_Selector_Obj sel : elements()) {
for (auto __sel = (elements()).begin(); __sel != (elements()).end(); ++__sel) { Simple_Selector_Obj sel = *(__sel);
if (sel->find(f)) return true;
}
// execute last
Expand Down Expand Up @@ -95,7 +95,7 @@ namespace Sass {

void Arguments::set_delayed(bool delayed)
{
for (Argument_Obj arg : elements()) {
for (auto __arg = (elements()).begin(); __arg != (elements()).end(); ++__arg) { Argument_Obj arg = *(__arg);
if (arg) arg->set_delayed(delayed);
}
is_delayed(delayed);
Expand Down Expand Up @@ -168,15 +168,15 @@ namespace Sass {

bool Compound_Selector::has_parent_ref() const
{
for (Simple_Selector_Obj s : elements()) {
for (auto __s = (elements()).begin(); __s != (elements()).end(); ++__s) { Simple_Selector_Obj s = *(__s);
if (s && s->has_parent_ref()) return true;
}
return false;
}

bool Compound_Selector::has_real_parent_ref() const
{
for (Simple_Selector_Obj s : elements()) {
for (auto __s = (elements()).begin(); __s != (elements()).end(); ++__s) { Simple_Selector_Obj s = *(__s);
if (s && s->has_real_parent_ref()) return true;
}
return false;
Expand Down Expand Up @@ -843,7 +843,7 @@ namespace Sass {

bool Compound_Selector::is_superselector_of(Selector_List_Obj rhs, std::string wrapped)
{
for (Complex_Selector_Obj item : rhs->elements()) {
for (auto __item = (rhs->elements()).begin(); __item != (rhs->elements()).end(); ++__item) { Complex_Selector_Obj item = *(__item);
if (is_superselector_of(item, wrapped)) return true;
}
return false;
Expand Down Expand Up @@ -960,8 +960,8 @@ namespace Sass {
rset.insert(r->to_string());
}

//for (auto l : lset) { cerr << "l: " << l << endl; }
//for (auto r : rset) { cerr << "r: " << r << endl; }
//for (auto __l = (lset).begin(); __l != (lset).end(); ++__l) { auto l = *(__l); cerr << "l: " << l << endl; }
//for (auto __r = (rset).begin(); __r != (rset).end(); ++__r) { auto r = *(__r); cerr << "r: " << r << endl; }

if (lset.empty()) return true;
// return true if rset contains all the elements of lset
Expand Down Expand Up @@ -1403,7 +1403,7 @@ namespace Sass {
retval = this->tails(tails);
}

for (Simple_Selector_Obj ss : head->elements()) {
for (auto __ss = (head->elements()).begin(); __ss != (head->elements()).end(); ++__ss) { Simple_Selector_Obj ss = *(__ss);
if (Wrapped_Selector_Ptr ws = Cast<Wrapped_Selector>(ss)) {
if (Selector_List_Ptr sl = Cast<Selector_List>(ws->selector())) {
if (parents) ws->selector(sl->resolve_parent_refs(pstack, implicit_parent));
Expand Down Expand Up @@ -1563,15 +1563,15 @@ namespace Sass {

bool Selector_List::has_parent_ref() const
{
for (Complex_Selector_Obj s : elements()) {
for (auto __s = (elements()).begin(); __s != (elements()).end(); ++__s) { Complex_Selector_Obj s = *(__s);
if (s && s->has_parent_ref()) return true;
}
return false;
}

bool Selector_List::has_real_parent_ref() const
{
for (Complex_Selector_Obj s : elements()) {
for (auto __s = (elements()).begin(); __s != (elements()).end(); ++__s) { Complex_Selector_Obj s = *(__s);
if (s && s->has_real_parent_ref()) return true;
}
return false;
Expand Down Expand Up @@ -1672,7 +1672,7 @@ namespace Sass {
{

Selector_List_Ptr extender = this;
for (auto complex_sel : extendee->elements()) {
for (auto __complex_sel = (extendee->elements()).begin(); __complex_sel != (extendee->elements()).end(); ++__complex_sel) { auto complex_sel = *(__complex_sel);
Complex_Selector_Obj c = complex_sel;


Expand Down Expand Up @@ -1741,7 +1741,7 @@ namespace Sass {
Argument_Obj Arguments::get_rest_argument()
{
if (this->has_rest_argument()) {
for (Argument_Obj arg : this->elements()) {
for (auto __arg = (this->elements()).begin(); __arg != (this->elements()).end(); ++__arg) { Argument_Obj arg = *(__arg);
if (arg->is_rest_argument()) {
return arg;
}
Expand All @@ -1753,7 +1753,7 @@ namespace Sass {
Argument_Obj Arguments::get_keyword_argument()
{
if (this->has_keyword_argument()) {
for (Argument_Obj arg : this->elements()) {
for (auto __arg = (this->elements()).begin(); __arg != (this->elements()).end(); ++__arg) { Argument_Obj arg = *(__arg);
if (arg->is_keyword_argument()) {
return arg;
}
Expand Down Expand Up @@ -1924,8 +1924,7 @@ namespace Sass {
denominator_units_.clear();

// build them by iterating over the exponents
for (auto exp : exponents)
{
for (auto __exp = (exponents).begin(); __exp != (exponents).end(); ++__exp) { auto exp = *(__exp);
// maybe there is more effecient way to push
// the same item multiple times to a vector?
for(size_t i = 0, S = abs(exp.second); i < S; ++i)
Expand Down Expand Up @@ -2136,8 +2135,7 @@ namespace Sass {
denominator_units_.clear();

// build them by iterating over the exponents
for (auto exp : exponents)
{
for (auto __exp = (exponents).begin(); __exp != (exponents).end(); ++__exp) { auto exp = *(__exp);
// maybe there is more effecient way to push
// the same item multiple times to a vector?
for(size_t i = 0, S = abs(exp.second); i < S; ++i)
Expand Down Expand Up @@ -2312,7 +2310,7 @@ namespace Sass {
{
if (Map_Ptr_Const r = Cast<Map>(&rhs)) {
if (length() != r->length()) return false;
for (auto key : keys()) {
for (auto __key = (keys()).begin(); __key != (keys()).end(); ++__key) { auto key = *(__key);
Expression_Obj lv = at(key);
Expression_Obj rv = r->at(key);
if (!rv || !lv) return false;
Expand Down Expand Up @@ -2405,7 +2403,7 @@ namespace Sass {
List_Obj Map::to_list(ParserState& pstate) {
List_Obj ret = SASS_MEMORY_NEW(List, pstate, length(), SASS_COMMA);

for (auto key : keys()) {
for (auto __key = (keys()).begin(); __key != (keys()).end(); ++__key) { auto key = *(__key);
List_Obj l = SASS_MEMORY_NEW(List, pstate, 2);
l->append(key);
l->append(at(key));
Expand Down
24 changes: 10 additions & 14 deletions src/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ namespace Sass {
virtual size_t hash()
{
if (hash_ == 0) {
for (T& el : elements_) {
for (auto __el = (elements_).begin(); __el != (elements_).end(); ++__el) { T& el = *(__el);
hash_combine(hash_, el->hash());
}
}
Expand Down Expand Up @@ -395,7 +395,7 @@ namespace Sass {
return *this;
}

for (auto key : h->keys()) {
for (auto __key = (h->keys()).begin(); __key != (h->keys()).end(); ++__key) { auto key = *(__key);
*this << std::make_pair(key, h->at(key));
}

Expand Down Expand Up @@ -1137,7 +1137,7 @@ namespace Sass {
virtual size_t hash()
{
if (hash_ == 0) {
for (auto key : keys()) {
for (auto __key = (keys()).begin(); __key != (keys()).end(); ++__key) { auto key = *(__key);
hash_combine(hash_, key->hash());
hash_combine(hash_, at(key)->hash());
}
Expand Down Expand Up @@ -1477,8 +1477,7 @@ namespace Sass {
{
if (hash_ == 0) {
hash_ = std::hash<std::string>()(name());
for (auto argument : arguments()->elements())
{ hash_combine(hash_, argument->hash()); }
for (auto __argument = (arguments()->elements()).begin(); __argument != (arguments()->elements()).end(); ++__argument) { auto argument = *(__argument); hash_combine(hash_, argument->hash()); }
}
return hash_;
}
Expand Down Expand Up @@ -1582,10 +1581,8 @@ namespace Sass {
{
if (hash_ == 0) {
hash_ = std::hash<double>()(value_);
for (const auto numerator : numerator_units())
{ hash_combine(hash_, std::hash<std::string>()(numerator)); }
for (const auto denominator : denominator_units())
{ hash_combine(hash_, std::hash<std::string>()(denominator)); }
for (auto __numerator = (numerator_units()).begin(); __numerator != (numerator_units()).end(); ++__numerator) { const auto numerator = *(__numerator); hash_combine(hash_, std::hash<std::string>()(numerator)); }
for (auto __denominator = (denominator_units()).begin(); __denominator != (denominator_units()).end(); ++__denominator) { const auto denominator = *(__denominator); hash_combine(hash_, std::hash<std::string>()(denominator)); }
}
return hash_;
}
Expand Down Expand Up @@ -1757,7 +1754,7 @@ namespace Sass {
bool is_right_interpolant(void) const;
// void has_interpolants(bool tc) { }
bool has_interpolants() {
for (auto el : elements()) {
for (auto __el = (elements()).begin(); __el != (elements()).end(); ++__el) { auto el = *(__el);
if (el->is_interpolant()) return true;
}
return false;
Expand All @@ -1767,8 +1764,7 @@ namespace Sass {
virtual size_t hash()
{
if (hash_ == 0) {
for (auto string : elements())
{ hash_combine(hash_, string->hash()); }
for (auto __string = (elements()).begin(); __string != (elements()).end(); ++__string) { auto string = *(__string); hash_combine(hash_, string->hash()); }
}
return hash_;
}
Expand Down Expand Up @@ -2978,12 +2974,12 @@ namespace Sass {
}
virtual void set_media_block(Media_Block_Ptr mb) {
media_block(mb);
for (Complex_Selector_Obj cs : elements()) {
for (auto __cs = (elements()).begin(); __cs != (elements()).end(); ++__cs) { Complex_Selector_Obj cs = *(__cs);
cs->set_media_block(mb);
}
}
virtual bool has_placeholder() {
for (Complex_Selector_Obj cs : elements()) {
for (auto __cs = (elements()).begin(); __cs != (elements()).end(); ++__cs) { Complex_Selector_Obj cs = *(__cs);
if (cs->has_placeholder()) return true;
}
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace Sass {
rest->separator(),
true);
// wrap each item from list as an argument
for (Expression_Obj item : rest->elements()) {
for (auto __item = (rest->elements()).begin(); __item != (rest->elements()).end(); ++__item) { Expression_Obj item = *(__item);
if (Argument_Obj arg = Cast<Argument>(item)) {
arglist->append(SASS_MEMORY_COPY(arg)); // copy
} else {
Expand All @@ -96,7 +96,7 @@ namespace Sass {
List_Ptr arglist = SASS_MEMORY_NEW(List, p->pstate(), 0, SASS_COMMA, true);
env->local_frame()[p->name()] = arglist;
Map_Obj argmap = Cast<Map>(a->value());
for (auto key : argmap->keys()) {
for (auto __key = (argmap->keys()).begin(); __key != (argmap->keys()).end(); ++__key) { auto key = *(__key);
if (String_Constant_Obj str = Cast<String_Constant>(key)) {
std::string param = unquote(str->value());
arglist->append(SASS_MEMORY_NEW(Argument,
Expand Down Expand Up @@ -217,7 +217,7 @@ namespace Sass {
} else if (a->is_keyword_argument()) {
Map_Obj argmap = Cast<Map>(a->value());

for (auto key : argmap->keys()) {
for (auto __key = (argmap->keys()).begin(); __key != (argmap->keys()).end(); ++__key) { auto key = *(__key);
std::string param = "$" + unquote(Cast<String_Constant>(key)->value());

if (!param_map.count(param)) {
Expand Down
8 changes: 4 additions & 4 deletions src/check_nesting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace Sass {
}

if (b) {
for (auto n : b->elements()) {
for (auto __n = (b->elements()).begin(); __n != (b->elements()).end(); ++__n) { auto n = *(__n);
n->perform(this);
}
}
Expand Down Expand Up @@ -179,7 +179,7 @@ namespace Sass {

// void CheckNesting::invalid_import_parent(Statement_Ptr parent)
// {
// for (auto pp : this->parents) {
// for (auto __pp = (this->parents).begin(); __pp != (this->parents).end(); ++__pp) { auto pp = *(__pp);
// if (
// Cast<Each>(pp) ||
// Cast<For>(pp) ||
Expand Down Expand Up @@ -210,7 +210,7 @@ namespace Sass {

void CheckNesting::invalid_mixin_definition_parent(Statement_Ptr parent)
{
for (Statement_Ptr pp : this->parents) {
for (auto __pp = (this->parents).begin(); __pp != (this->parents).end(); ++__pp) { Statement_Ptr pp = *(__pp);
if (
Cast<Each>(pp) ||
Cast<For>(pp) ||
Expand All @@ -230,7 +230,7 @@ namespace Sass {

void CheckNesting::invalid_function_parent(Statement_Ptr parent)
{
for (Statement_Ptr pp : this->parents) {
for (auto __pp = (this->parents).begin(); __pp != (this->parents).end(); ++__pp) { Statement_Ptr pp = *(__pp);
if (
Cast<Each>(pp) ||
Cast<For>(pp) ||
Expand Down
10 changes: 5 additions & 5 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ namespace Sass {
collect_plugin_paths(c_options.plugin_paths);

// load plugins and register custom behaviors
for(auto plug : plugin_paths) { plugins.load_plugins(plug); }
for(auto fn : plugins.get_headers()) { c_headers.push_back(fn); }
for(auto fn : plugins.get_importers()) { c_importers.push_back(fn); }
for(auto fn : plugins.get_functions()) { c_functions.push_back(fn); }
for (auto __plug = (plugin_paths).begin(); __plug != (plugin_paths).end(); ++__plug) { auto plug = *(__plug); plugins.load_plugins(plug); }
for (auto __fn = (plugins.get_headers()).begin(); __fn != (plugins.get_headers()).end(); ++__fn) { auto fn = *(__fn); c_headers.push_back(fn); }
for (auto __fn = (plugins.get_importers()).begin(); __fn != (plugins.get_importers()).end(); ++__fn) { auto fn = *(__fn); c_importers.push_back(fn); }
for (auto __fn = (plugins.get_functions()).begin(); __fn != (plugins.get_functions()).end(); ++__fn) { auto fn = *(__fn); c_functions.push_back(fn); }

// sort the items by priority (lowest first)
sort (c_headers.begin(), c_headers.end(), sort_importers);
Expand Down Expand Up @@ -419,7 +419,7 @@ namespace Sass {
// need one correct import
bool has_import = false;
// process all custom importers (or custom headers)
for (Sass_Importer_Entry& importer_ent : importers) {
for (auto __importer_ent = (importers).begin(); __importer_ent != (importers).end(); ++__importer_ent) { Sass_Importer_Entry& importer_ent = *(__importer_ent);
// int priority = sass_importer_get_priority(importer);
Sass_Importer_Fn fn = sass_importer_get_function(importer_ent);
// skip importer if it returns NULL
Expand Down
Loading

0 comments on commit 47c834b

Please sign in to comment.