Skip to content

Commit 6d154cc

Browse files
committed
fixed include and compiler error
- removed another copy of ContextValue - made functions not changing internal const
1 parent 22ce6f7 commit 6d154cc

File tree

2 files changed

+12
-44
lines changed

2 files changed

+12
-44
lines changed

.vscode/launch.json

Lines changed: 0 additions & 33 deletions
This file was deleted.

api/include/opentelemetry/context/context.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#pragma once
55

6-
#include <cstring>
6+
#include <string>
77
#include <utility>
88

99
#include "opentelemetry/context/context_value.h"
@@ -34,15 +34,15 @@ class Context
3434

3535
// Creates a context object from a key and value, this will
3636
// hold a shared_ptr to the head of the DataList linked list
37-
Context(nostd::string_view key, ContextValue value) noexcept
37+
Context(nostd::string_view key, const ContextValue &value) noexcept
3838
: head_{nostd::shared_ptr<DataList>{new DataList(key, value)}}
3939
{}
4040

4141
// Accepts a new iterable and then returns a new context that
4242
// contains the new key and value data. It attaches the
4343
// exisiting list to the end of the new list.
4444
template <class T>
45-
Context SetValues(T &values) noexcept
45+
Context SetValues(T &values) const noexcept
4646
{
4747
Context context(values);
4848
auto last = context.head_;
@@ -57,9 +57,9 @@ class Context
5757
// Accepts a new iterable and then returns a new context that
5858
// contains the new key and value data. It attaches the
5959
// exisiting list to the end of the new list.
60-
Context SetValue(nostd::string_view key, const ContextValue& value) noexcept
60+
Context SetValue(nostd::string_view key, const ContextValue& value) const noexcept
6161
{
62-
Context context = Context(key, value);
62+
Context context(key, value);
6363
context.head_->next_ = head_;
6464
return context;
6565
}
@@ -101,23 +101,24 @@ class Context
101101
template <class T>
102102
DataList(const T &keys_and_vals)
103103
{
104-
auto *node = this;
105104
auto iter = std::begin(keys_and_vals);
106-
*node = DataList(iter.first, iter.second);
105+
if (iter == std::end(keys_and_vals))
106+
return;
107+
auto *node = this;
108+
*node = DataList(iter->first, iter->second);
107109
for (++iter; iter != std::end(keys_and_vals); ++iter)
108110
{
109-
node->next_ = nostd::shared_ptr<DataList>(new DataList(iter.first, iter.second));
111+
node->next_ = nostd::shared_ptr<DataList>(new DataList(iter->first, iter->second));
110112
node = node->next_.get();
111113
}
112114
}
113115

114116
// Builds a data list with just a key and value, so it will just be the head
115117
// and returns that head.
116118
DataList(nostd::string_view key, const ContextValue &value)
119+
: key_(key.begin(), key.end())
120+
, value_( value)
117121
{
118-
key_.assign(key.begin(), key.end());
119-
next_ = nostd::shared_ptr<DataList>{nullptr};
120-
value_ = value;
121122
}
122123
};
123124

0 commit comments

Comments
 (0)