Skip to content

Commit 562ed93

Browse files
tniessenbmeck
authored andcommitted
src: improve node::Dotenv declarations
There is no need to explicitly allow copy constructor and copy assignment, and some of these functions should be marked as const. PR-URL: nodejs#52973 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 45a6d88 commit 562ed93

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/node_dotenv.cc

+2-6
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ std::vector<std::string> Dotenv::GetPathFromArgs(
4242
}
4343

4444
void Dotenv::SetEnvironment(node::Environment* env) {
45-
if (store_.empty()) {
46-
return;
47-
}
48-
4945
auto isolate = env->isolate();
5046

5147
for (const auto& entry : store_) {
@@ -67,7 +63,7 @@ void Dotenv::SetEnvironment(node::Environment* env) {
6763
}
6864
}
6965

70-
Local<Object> Dotenv::ToObject(Environment* env) {
66+
Local<Object> Dotenv::ToObject(Environment* env) const {
7167
Local<Object> result = Object::New(env->isolate());
7268

7369
for (const auto& entry : store_) {
@@ -263,7 +259,7 @@ Dotenv::ParseResult Dotenv::ParsePath(const std::string_view path) {
263259
return ParseResult::Valid;
264260
}
265261

266-
void Dotenv::AssignNodeOptionsIfAvailable(std::string* node_options) {
262+
void Dotenv::AssignNodeOptionsIfAvailable(std::string* node_options) const {
267263
auto match = store_.find("NODE_OPTIONS");
268264

269265
if (match != store_.end()) {

src/node_dotenv.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ class Dotenv {
1515
enum ParseResult { Valid, FileError, InvalidContent };
1616

1717
Dotenv() = default;
18-
Dotenv(const Dotenv& d) = default;
18+
Dotenv(const Dotenv& d) = delete;
1919
Dotenv(Dotenv&& d) noexcept = default;
2020
Dotenv& operator=(Dotenv&& d) noexcept = default;
21-
Dotenv& operator=(const Dotenv& d) = default;
21+
Dotenv& operator=(const Dotenv& d) = delete;
2222
~Dotenv() = default;
2323

2424
void ParseContent(const std::string_view content);
2525
ParseResult ParsePath(const std::string_view path);
26-
void AssignNodeOptionsIfAvailable(std::string* node_options);
26+
void AssignNodeOptionsIfAvailable(std::string* node_options) const;
2727
void SetEnvironment(Environment* env);
28-
v8::Local<v8::Object> ToObject(Environment* env);
28+
v8::Local<v8::Object> ToObject(Environment* env) const;
2929

3030
static std::vector<std::string> GetPathFromArgs(
3131
const std::vector<std::string>& args);

0 commit comments

Comments
 (0)