@@ -29,16 +29,14 @@ class Context
29
29
// hold a shared_ptr to the head of the DataList linked list
30
30
template <class T >
31
31
Context (const T &keys_and_values) noexcept
32
- {
33
- head_ = nostd::shared_ptr<DataList>{new DataList (keys_and_values)};
34
- }
32
+ : head_{nostd::shared_ptr<DataList>{new DataList (keys_and_values)}}
33
+ {}
35
34
36
35
// Creates a context object from a key and value, this will
37
36
// hold a shared_ptr to the head of the DataList linked list
38
37
Context (nostd::string_view key, ContextValue value) noexcept
39
- {
40
- head_ = nostd::shared_ptr<DataList>{new DataList (key, value)};
41
- }
38
+ : head_{nostd::shared_ptr<DataList>{new DataList (key, value)}}
39
+ {}
42
40
43
41
// Accepts a new iterable and then returns a new context that
44
42
//
29C2
contains the new key and value data. It attaches the
@@ -92,22 +90,21 @@ class Context
92
90
93
91
private:
94
92
// A linked list to contain the keys and values of this context node
95
- class DataList
93
+ struct DataList
96
94
{
97
- public:
98
- char *key_;
95
+ char *key_ = nullptr ;
99
96
100
- nostd::shared_ptr<DataList> next_;
97
+ nostd::shared_ptr<DataList> next_{ nullptr } ;
101
98
102
- size_t key_length_;
99
+ size_t key_length_ = 0UL ;
103
100
104
101
ContextValue value_;
105
102
106
- DataList () { next_ = nullptr ; }
103
+ DataList () = default ;
107
104
108
105
// Builds a data list off of a key and value iterable and returns the head
109
106
template <class T >
110
- DataList (const T &keys_and_vals) : key_{ nullptr }, next_(nostd::shared_ptr<DataList>{ nullptr })
107
+ DataList (const T &keys_and_vals)
111
108
{
112
109
bool first = true ;
113
110
auto *node = this ;
@@ -132,9 +129,18 @@ class Context
132
129
{
133
130
key_ = new char [key.size ()];
134
131
key_length_ = key.size ();
135
- memcpy (key_, key.data (), key.size () * sizeof (char ));
136
- value_ = value;
132
+ std::memcpy (key_, key.data (), key.size () * sizeof (char ));
137
133
next_ = nostd::shared_ptr<DataList>{nullptr };
134
+ value_ = value;
135
+ }
136
+
137
+ DataList (const DataList &other)
138
+ : key_(new char [other.key_length_]),
139
+ next_ (other.next_),
140
+ key_length_(other.key_length_),
141
+ value_(other.value_)
142
+ {
143
+ std::memcpy (key_, other.key_ , other.key_length_ * sizeof (char ));
138
144
}
139
145
140
146
DataList &operator =(DataList &&other) noexcept
0 commit comments