Skip to content

Commit c00da14

Browse files
committed
Use template for environment map implementation
1 parent 9e38152 commit c00da14

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/ast_fwd_decl.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@ namespace Sass {
414414
typedef std::set<Compound_Selector_Obj, OrderNodes> CompoundSelectorSet;
415415
typedef std::unordered_set<Simple_Selector_Obj, HashNodes, CompareNodes> SimpleSelectorDict;
416416

417+
// only to switch implementations for testing
418+
#define environment_map std::map
419+
417420
// ###########################################################################
418421
// explicit type conversion functions
419422
// ###########################################################################

src/environment.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ namespace Sass {
66

77
template <typename T>
88
Environment<T>::Environment(bool is_shadow)
9-
: local_frame_(std::map<std::string, T>()),
9+
: local_frame_(environment_map<std::string, T>()),
1010
parent_(0), is_shadow_(false)
1111
{ }
1212
template <typename T>
1313
Environment<T>::Environment(Environment<T>* env, bool is_shadow)
14-
: local_frame_(std::map<std::string, T>()),
14+
: local_frame_(environment_map<std::string, T>()),
1515
parent_(env), is_shadow_(is_shadow)
1616
{ }
1717
template <typename T>
1818
Environment<T>::Environment(Environment<T>& env, bool is_shadow)
19-
: local_frame_(std::map<std::string, T>()),
19+
: local_frame_(environment_map<std::string, T>()),
2020
parent_(&env), is_shadow_(is_shadow)
2121
{ }
2222

@@ -45,7 +45,7 @@ namespace Sass {
4545
}
4646

4747
template <typename T>
48-
std::map<std::string, T>& Environment<T>::local_frame() {
48+
environment_map<std::string, T>& Environment<T>::local_frame() {
4949
return local_frame_;
5050
}
5151

@@ -177,7 +177,7 @@ namespace Sass {
177177
size_t indent = 0;
178178
if (parent_) indent = parent_->print(prefix) + 1;
179179
std::cerr << prefix << std::string(indent, ' ') << "== " << this << std::endl;
180-
for (typename std::map<std::string, T>::iterator i = local_frame_.begin(); i != local_frame_.end(); ++i) {
180+
for (typename environment_map<std::string, T>::iterator i = local_frame_.begin(); i != local_frame_.end(); ++i) {
181181
if (!ends_with(i->first, "[f]") && !ends_with(i->first, "[f]4") && !ends_with(i->first, "[f]2")) {
182182
std::cerr << prefix << std::string(indent, ' ') << i->first << " " << i->second;
183183
if (Value_Ptr val = Cast<Value>(i->second))

src/environment.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#define SASS_ENVIRONMENT_H
33

44
#include <string>
5-
#include <map>
6-
75
#include "ast_fwd_decl.hpp"
86
#include "ast_def_macros.hpp"
97

@@ -12,7 +10,7 @@ namespace Sass {
1210
template <typename T>
1311
class Environment {
1412
// TODO: test with map
15-
std::map<std::string, T> local_frame_;
13+
environment_map<std::string, T> local_frame_;
1614
ADD_PROPERTY(Environment*, parent)
1715
ADD_PROPERTY(bool, is_shadow)
1816

@@ -37,7 +35,7 @@ namespace Sass {
3735

3836
// scope operates on the current frame
3937

40-
std::map<std::string, T>& local_frame();
38+
environment_map<std::string, T>& local_frame();
4139

4240
bool has_local(const std::string& key) const;
4341

0 commit comments

Comments
 (0)