This repository was archived by the owner on Oct 24, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -236,6 +236,7 @@ namespace Sass {
236236 virtual const T& at (size_t i) const { return elements_.at (i); }
237237 virtual T& at (size_t i) { return elements_.at (i); }
238238 const T& get (size_t i) const { return elements_[i]; }
239+ // ToDo: might insert am item (update ordered list)
239240 const T& operator [](size_t i) const { return elements_[i]; }
240241
241242 // Implicitly get the std::vector from our object
Original file line number Diff line number Diff line change 11#ifndef SASS_ORDERED_MAP_H
22#define SASS_ORDERED_MAP_H
33
4+ #include < unordered_map>
5+
46namespace Sass {
57
68 // ##########################################################################
@@ -27,6 +29,8 @@ namespace Sass {
2729
2830 // Keep insertion order
2931 std::vector<Key> _keys;
32+ // That does not makes sense
33+ // Value might be updated ...
3034 std::vector<T> _values;
3135
3236 const KeyEqual _keyEqual;
@@ -91,6 +95,16 @@ namespace Sass {
9195 throw std::runtime_error (" Key does not exist" );
9296 }
9397
98+ T& operator [](const std::string& key) {
99+ if (hasKey (key)) {
100+ return _map[key];
101+ }
102+ T& value = _map[key];
103+ _keys.push_back (key);
104+ _values.push_back (value);
105+ return value;
106+ }
107+
94108 using iterator = typename std::vector<Key>::iterator;
95109 using const_iterator = typename std::vector<Key>::const_iterator;
96110 using reverse_iterator = typename std::vector<Key>::reverse_iterator;
Original file line number Diff line number Diff line change 33#include < stdexcept>
44#include < algorithm>
55#include " units.hpp"
6+ #include " ordered_map.hpp"
67#include " error_handling.hpp"
78
89namespace Sass {
@@ -285,7 +286,7 @@ namespace Sass {
285286 // it seems that a map table will fit nicely to do this
286287 // we basically construct exponents for each unit
287288 // has the advantage that they will be pre-sorted
288- std::map <std::string, int > exponents;
289+ ordered_map <std::string, int > exponents;
289290
290291 // initialize by summing up occurences in unit vectors
291292 // this will already cancel out equivalent units (e.q. px/px)
@@ -311,12 +312,12 @@ namespace Sass {
311312 denominators.clear ();
312313
313314 // recreate sorted units vectors
314- for (auto exp : exponents) {
315- int &exponent = exp. second ;
315+ for (auto key : exponents) {
316+ int &exponent = exponents[key] ;
316317 while (exponent > 0 && exponent --)
317- numerators.push_back (exp. first );
318+ numerators.push_back (key );
318319 while (exponent < 0 && exponent ++)
319- denominators.push_back (exp. first );
320+ denominators.push_back (key );
320321 }
321322
322323 // return for conversion
You can’t perform that action at this time.
0 commit comments