Skip to content

Commit ea5b716

Browse files
committed
Add a few minor code improvements
1 parent b10866c commit ea5b716

File tree

10 files changed

+46
-22
lines changed

10 files changed

+46
-22
lines changed

src/mapping.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define SASS_MAPPING_H
33

44
#include "position.hpp"
5+
#include "backtrace.hpp"
56

67
namespace Sass {
78

src/memory/allocator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "../sass.hpp"
2-
#include "../memory.hpp"
2+
#include "allocator.hpp"
3+
#include "memory_pool.hpp"
34

45
#if defined (_MSC_VER) // Visual studio
56
#define thread_local __declspec( thread )

src/memory/allocator.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ namespace std {
133133
};
134134
}
135135

136-
137136
#endif
138137

139138
#endif

src/memory/memory_pool.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#ifndef SASS_MEMORY_POOL_H
22
#define SASS_MEMORY_POOL_H
33

4-
#include "../sass.hpp"
5-
#include "../memory.hpp"
4+
#include <stdlib.h>
5+
#include <iostream>
6+
#include <algorithm>
67
#include <climits>
8+
#include <vector>
79

810
namespace Sass {
911

src/permutate.hpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ namespace Sass {
77

88
// Returns a list of all possible paths through the given lists.
99
//
10-
// For example, given `[[1, 2], [3, 4], [5]]`, this returns:
10+
// For example, given `[[1, 2], [3, 4], [5, 6]]`, this returns:
1111
//
1212
// ```
1313
// [[1, 3, 5],
1414
// [2, 3, 5],
1515
// [1, 4, 5],
16-
// [2, 4, 5]]
16+
// [2, 4, 5],
17+
// [1, 3, 6],
18+
// [2, 3, 6],
19+
// [1, 4, 6],
20+
// [2, 4, 6]]
1721
// ```
1822
//
1923
// Note: called `paths` in dart-sass
@@ -74,7 +78,22 @@ namespace Sass {
7478
}
7579
// EO permutate
7680

77-
// ToDo: this variant is used in resolve_parent_refs
81+
// ToDo: this variant is used in resolveParentSelectors
82+
// Returns a list of all possible paths through the given lists.
83+
//
84+
// For example, given `[[1, 2], [3, 4], [5, 6]]`, this returns:
85+
//
86+
// ```
87+
// [[1, 3, 5],
88+
// [1, 3, 6],
89+
// [1, 4, 5],
90+
// [1, 4, 6],
91+
// [2, 3, 5],
92+
// [2, 3, 6],
93+
// [2, 4, 5],
94+
// [2, 4, 6]]
95+
// ```
96+
//
7897
template <class T>
7998
sass::vector<sass::vector<T>>
8099
permutateAlt(const sass::vector<sass::vector<T>>& in) {
@@ -89,7 +108,7 @@ namespace Sass {
89108
}
90109

91110
size_t* state = new size_t[L];
92-
sass::vector< sass::vector<T>> out;
111+
sass::vector<sass::vector<T>> out;
93112

94113
// First initialize all states for every permutation group
95114
for (size_t i = 0; i < L; i += 1) {

src/sass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ extern "C" {
4646

4747
char* ADDCALL sass_copy_c_string(const char* str)
4848
{
49+
if (str == nullptr) return nullptr;
4950
size_t len = strlen(str) + 1;
5051
char* cpy = (char*) sass_alloc_memory(len);
5152
std::memcpy(cpy, str, len);

src/sass_values.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,7 @@ extern "C" {
340340
rv = Operators::op_colors(op, *l_c, *r_c, options, l_c->pstate());
341341
}
342342
else /* convert other stuff to string and apply operation */ {
343-
Value* l_v = Cast<Value>(lhs);
344-
Value* r_v = Cast<Value>(rhs);
345-
rv = Operators::op_strings(op, *l_v, *r_v, options, l_v->pstate());
343+
rv = Operators::op_strings(op, *lhs, *rhs, options, lhs->pstate());
346344
}
347345

348346
// ToDo: maybe we should should return null value?

src/source_map.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include "position.hpp"
1010
#include "mapping.hpp"
1111

12+
#include "backtrace.hpp"
13+
#include "memory.hpp"
14+
1215
#define VECTOR_PUSH(vec, ins) vec.insert(vec.end(), ins.begin(), ins.end())
1316
#define VECTOR_UNSHIFT(vec, ins) vec.insert(vec.begin(), ins.begin(), ins.end())
1417

@@ -49,7 +52,7 @@ namespace Sass {
4952
class OutputBuffer {
5053
public:
5154
OutputBuffer(void)
52-
: buffer(""),
55+
: buffer(),
5356
smap()
5457
{ }
5558
public:

src/utf8_string.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,32 @@
1111

1212
namespace Sass {
1313
namespace UTF_8 {
14-
using sass::string;
1514

1615
// naming conventions:
1716
// offset: raw byte offset (0 based)
1817
// position: code point offset (0 based)
1918
// index: code point offset (1 based or negative)
2019

2120
// function that will count the number of code points (utf-8 characters) from the given beginning to the given end
22-
size_t code_point_count(const string& str, size_t start, size_t end) {
21+
size_t code_point_count(const sass::string& str, size_t start, size_t end) {
2322
return utf8::distance(str.begin() + start, str.begin() + end);
2423
}
2524

26-
size_t code_point_count(const string& str) {
25+
size_t code_point_count(const sass::string& str) {
2726
return utf8::distance(str.begin(), str.end());
2827
}
2928

3029
// function that will return the byte offset at a code point position
31-
size_t offset_at_position(const string& str, size_t position) {
32-
string::const_iterator it = str.begin();
30+
size_t offset_at_position(const sass::string& str, size_t position) {
31+
sass::string::const_iterator it = str.begin();
3332
utf8::advance(it, position, str.end());
3433
return std::distance(str.begin(), it);
3534
}
3635

3736
// function that returns number of bytes in a character at offset
38-
size_t code_point_size_at_offset(const string& str, size_t offset) {
37+
size_t code_point_size_at_offset(const sass::string& str, size_t offset) {
3938
// get iterator from string and forward by offset
40-
string::const_iterator stop = str.begin() + offset;
39+
sass::string::const_iterator stop = str.begin() + offset;
4140
// check if beyond boundary
4241
if (stop == str.end()) return 0;
4342
// advance by one code point
@@ -78,9 +77,9 @@ namespace Sass {
7877
using std::wstring;
7978

8079
// convert from utf16/wide string to utf8 string
81-
string convert_from_utf16(const wstring& utf16)
80+
sass::string convert_from_utf16(const wstring& utf16)
8281
{
83-
string utf8;
82+
sass::string utf8;
8483
// pre-allocate expected memory
8584
utf8.reserve(sizeof(utf16)/2);
8685
utf8::utf16to8(utf16.begin(), utf16.end(),
@@ -89,7 +88,7 @@ namespace Sass {
8988
}
9089

9190
// convert from utf8 string to utf16/wide string
92-
wstring convert_to_utf16(const string& utf8)
91+
wstring convert_to_utf16(const sass::string& utf8)
9392
{
9493
wstring utf16;
9594
// pre-allocate expected memory

src/utf8_string.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <string>
55
#include "utf8.h"
6+
#include "memory.hpp"
67

78
namespace Sass {
89
namespace UTF_8 {

0 commit comments

Comments
 (0)