Skip to content

Commit 36c739d

Browse files
authored
fix: item attribute (#511)
1 parent 19d5ddb commit 36c739d

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/items/functions/item/attribute.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const std::string &ItemAttribute::getAttributeString(ItemAttribute_t type) const
3535
return emptyString;
3636
}
3737

38-
return *attribute->getString();
38+
return attribute->getString();
3939
}
4040

4141
const int64_t &ItemAttribute::getAttributeValue(ItemAttribute_t type) const {

src/items/functions/item/attribute.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ class Attributes : public ItemAttributeHelper {
9494
return type;
9595
}
9696

97-
std::variant<int64_t, std::shared_ptr<std::string>> getDefaultValueForType(ItemAttribute_t attributeType) const {
97+
std::variant<int64_t, std::string> getDefaultValueForType(ItemAttribute_t attributeType) const {
9898
if (ItemAttributeHelper::isAttributeInteger(attributeType)) {
9999
return 0;
100100
} else if (ItemAttributeHelper::isAttributeString(attributeType)) {
101-
return std::make_shared<std::string>();
101+
return std::string();
102102
} else {
103103
return {};
104104
}
@@ -110,8 +110,8 @@ class Attributes : public ItemAttributeHelper {
110110
}
111111
}
112112
void setValue(const std::string &newValue) {
113-
if (std::holds_alternative<std::shared_ptr<std::string>>(value)) {
114-
value = std::make_shared<std::string>(newValue);
113+
if (std::holds_alternative<std::string>(value)) {
114+
value = newValue;
115115
}
116116
}
117117
const int64_t &getInteger() const {
@@ -122,17 +122,17 @@ class Attributes : public ItemAttributeHelper {
122122
return emptyValue;
123123
}
124124

125-
std::shared_ptr<std::string> getString() const {
126-
if (std::holds_alternative<std::shared_ptr<std::string>>(value)) {
127-
return std::get<std::shared_ptr<std::string>>(value);
125+
const std::string &getString() const {
126+
if (std::holds_alternative<std::string>(value)) {
127+
return std::get<std::string>(value);
128128
}
129-
static std::shared_ptr<std::string> emptyPtr;
130-
return emptyPtr;
129+
static std::string emptyValue;
130+
return emptyValue;
131131
}
132132

133133
private:
134134
ItemAttribute_t type;
135-
std::variant<int64_t, std::shared_ptr<std::string>> value;
135+
std::variant<int64_t, std::string> value;
136136
};
137137

138138
class ItemAttribute : public ItemAttributeHelper {

0 commit comments

Comments
 (0)