@@ -29,16 +29,14 @@ class Context
2929 // hold a shared_ptr to the head of the DataList linked list
3030 template <class T >
3131 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+ {}
3534
3635 // Creates a context object from a key and value, this will
3736 // hold a shared_ptr to the head of the DataList linked list
3837 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+ {}
4240
4341 // Accepts a new iterable and then returns a new context that
4442 // contains the new key and value data. It attaches the
@@ -92,22 +90,21 @@ class Context
9290
9391private:
9492 // A linked list to contain the keys and values of this context node
95- class DataList
93+ struct DataList
9694 {
97- public:
98- char *key_;
95+ char *key_ = nullptr ;
9996
100- nostd::shared_ptr<DataList> next_;
97+ nostd::shared_ptr<DataList> next_{ nullptr } ;
10198
102- size_t key_length_;
99+ size_t key_length_ = 0UL ;
103100
104101 ContextValue value_;
105102
106- DataList () { next_ = nullptr ; }
103+ DataList () = default ;
107104
108105 // Builds a data list off of a key and value iterable and returns the head
109106 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)
111108 {
112109 bool first = true ;
113110 auto *node = this ;
@@ -132,9 +129,18 @@ class Context
132129 {
133130 key_ = new char [key.size ()];
134131 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 ));
137133 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 ));
138144 }
139145
140146 DataList &operator =(DataList &&other) noexcept
0 commit comments