Commit 42a50269 by Aaron Leung

Working on refactoring/optimizing the node data structure.

parent 414e8f5f
...@@ -35,7 +35,6 @@ namespace Sass { ...@@ -35,7 +35,6 @@ namespace Sass {
struct Context { struct Context {
Environment global_env; Environment global_env;
vector<Node> pending;
vector<char*> source_refs; vector<char*> source_refs;
size_t ref_count; size_t ref_count;
......
...@@ -18,9 +18,9 @@ namespace Sass { ...@@ -18,9 +18,9 @@ namespace Sass {
{ {
Node n(*this); Node n(*this);
if (has_children) { if (has_children) {
n.contents.children = new vector<Node>; n.content.children = new vector<Node>;
++allocations; ++allocations;
n.contents.children->reserve(size()); n.content.children->reserve(size());
for (int i = 0; i < size(); ++i) { for (int i = 0; i < size(); ++i) {
n << at(i).clone(); n << at(i).clone();
} }
...@@ -149,8 +149,12 @@ namespace Sass { ...@@ -149,8 +149,12 @@ namespace Sass {
stringstream ss; stringstream ss;
// ss.setf(std::ios::fixed, std::ios::floatfield); // ss.setf(std::ios::fixed, std::ios::floatfield);
// ss.precision(3); // ss.precision(3);
ss << content.dimension.numeric_value ss << content.dimension.numeric_value;
<< string(Token(content.dimension.unit, identifier(content.dimension.unit))); Token unit;
unit.begin = content.dimension.unit;
unit.end = Prelexer::identifier(content.dimension.unit);
ss << string(unit);
// << string(Token(content.dimension.unit, Prelexer::identifier(content.dimension.unit)));
return ss.str(); return ss.str();
} break; } break;
...@@ -218,7 +222,7 @@ namespace Sass { ...@@ -218,7 +222,7 @@ namespace Sass {
string indentation(2*depth, ' '); string indentation(2*depth, ' ');
switch (type) { switch (type) {
case comment: case comment:
buf << indentation << string(token) << endl; buf << indentation << string(content.token) << endl;
break; break;
case ruleset: case ruleset:
buf << indentation; buf << indentation;
...@@ -238,8 +242,8 @@ namespace Sass { ...@@ -238,8 +242,8 @@ namespace Sass {
} }
break; break;
case selector_combinator: case selector_combinator:
if (std::isspace(token.begin[0])) buf << ' '; if (std::isspace(content.token.begin[0])) buf << ' ';
else buf << ' ' << string(token) << ' '; else buf << ' ' << string(content.token) << ' ';
break; break;
case simple_selector_sequence: case simple_selector_sequence:
for (int i = 0; i < size(); ++i) { for (int i = 0; i < size(); ++i) {
...@@ -247,7 +251,7 @@ namespace Sass { ...@@ -247,7 +251,7 @@ namespace Sass {
} }
break; break;
case simple_selector: case simple_selector:
buf << string(token); buf << string(content.token);
break; break;
case block: case block:
buf << " {" << endl; buf << " {" << endl;
...@@ -262,13 +266,13 @@ namespace Sass { ...@@ -262,13 +266,13 @@ namespace Sass {
buf << ';' << endl; buf << ';' << endl;
break; break;
case property: case property:
buf << string(token); buf << string(content.token);
break; break;
case values: case values:
for (int i = 0; i < size(); at(i++).echo(buf, depth)) ; for (int i = 0; i < size(); at(i++).echo(buf, depth)) ;
break; break;
case value: case value:
buf << ' ' << string(token); buf << ' ' << string(content.token);
break; break;
} }
} }
...@@ -434,13 +438,13 @@ namespace Sass { ...@@ -434,13 +438,13 @@ namespace Sass {
if (at(i).type == expansion) { if (at(i).type == expansion) {
Node expn = at(i); Node expn = at(i);
if (expn[0].has_expansions) expn.flatten(); if (expn[0].has_expansions) expn.flatten();
at(0).has_rules_or_comments |= expn[0].has_rules_or_comments; at(0).has_statements |= expn[0].has_statements;
at(0).has_rulesets |= expn[0].has_rulesets; at(0).has_blocks |= expn[0].has_blocks;
at(0).has_propsets |= expn[0].has_propsets; at(0).has_expansions |= expn[0].has_expansions;
at(0).has_expansions |= expn[0].has_expansions;
at(i).type = none; at(i).type = none;
children->insert(children->begin() + i, content.children->insert(content.children->begin() + i,
expn.children->begin(), expn.children->end()); expn.content.children->begin(),
expn.content.children->end());
} }
} }
} }
......
...@@ -54,7 +54,7 @@ namespace Sass { ...@@ -54,7 +54,7 @@ namespace Sass {
textual_dimension, textual_dimension,
textual_number, textual_number,
textual_hex, textual_hex,
color_name; color_name,
string_constant, string_constant,
numeric_percentage, numeric_percentage,
numeric_dimension, numeric_dimension,
......
...@@ -9,8 +9,8 @@ namespace Sass { ...@@ -9,8 +9,8 @@ namespace Sass {
const char* begin; const char* begin;
const char* end; const char* end;
Token(); // Token();
Token(const char* begin, const char* end); // Token(const char* begin, const char* end);
size_t length() const size_t length() const
{ return end - begin; } { return end - begin; }
...@@ -29,7 +29,7 @@ namespace Sass { ...@@ -29,7 +29,7 @@ namespace Sass {
}; };
struct Dimension { struct Dimension {
const double numeric_value; double numeric_value;
const char* unit; const char* unit;
}; };
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment