Skip to content

Commit cc6171a

Browse files
committed
perf: add in and safe to more functions
1 parent 215766e commit cc6171a

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

Readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ minifyFiles(["file1.json", "file2.json"], true);
9090

9191
```
9292
❯ node .\benchmark\native-benchmark.mjs
93-
0.989 seconds
93+
0.977 seconds
9494
9595
❯ node .\benchmark\js-benchmark.mjs
96-
58.686 seconds
96+
58.818 seconds
9797
```
9898

9999
### Contributing

src/native/lib.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const spaceOrBreakRegex = ctRegex!(`\s`);
1717
Return:
1818
the minified json string
1919
*/
20-
string minifyString(string jsonString, bool hasComment = false) @trusted
20+
string minifyString(in string jsonString, in bool hasComment = false) @trusted
2121
{
2222
auto in_string = false;
2323
auto in_multiline_comment = false;
@@ -121,7 +121,7 @@ private bool hasNoSlashOrEvenNumberOfSlashes(in string leftContextSubstr) @safe
121121
return slashCount % 2 == 0;
122122
}
123123

124-
private bool notSlashAndNoSpaceOrBreak(string matchFrontHit)
124+
private bool notSlashAndNoSpaceOrBreak(in string matchFrontHit) @safe
125125
{
126126
return matchFrontHit != "\"" && matchFrontHit.matchFirst(spaceOrBreakRegex).empty();
127127
}
@@ -133,7 +133,7 @@ private bool notSlashAndNoSpaceOrBreak(string matchFrontHit)
133133
files = the paths to the files.
134134
hasComment = a boolean to support comments in json. Default: `false`.
135135
*/
136-
void minifyFiles(string[] files, bool hasComment = false)
136+
void minifyFiles(in string[] files, in bool hasComment = false)
137137
{
138138
import std.parallelism : parallel;
139139
import std.file : readText, write;

src/native/libc.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extern (C):
1414
Return:
1515
the minified json string
1616
*/
17-
auto minifyString(char* jsonCString, bool hasComment = false)
17+
auto minifyString(in char* jsonCString, in bool hasComment = false)
1818
{
1919
import std : fromStringz, toStringz;
2020

0 commit comments

Comments
 (0)