Skip to content

Commit 406d218

Browse files
committed
use reference_wrapper instead of raw pointer
1 parent 855e023 commit 406d218

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

src/iceberg/schema.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,16 @@ bool Schema::Equals(const Schema& other) const {
9090
Result<std::optional<std::reference_wrapper<const SchemaField>>> Schema::FindFieldByName(
9191
std::string_view name, bool case_sensitive) const {
9292
if (case_sensitive) {
93-
ICEBERG_ASSIGN_OR_RAISE(auto* name_to_id, name_to_id_.Get(*this));
94-
auto it = name_to_id->find(name);
95-
if (it == name_to_id->end()) {
93+
ICEBERG_ASSIGN_OR_RAISE(auto name_to_id, name_to_id_.Get(*this));
94+
auto it = name_to_id.get().find(name);
95+
if (it == name_to_id.get().end()) {
9696
return std::nullopt;
9797
};
9898
return FindFieldById(it->second);
9999
}
100-
ICEBERG_ASSIGN_OR_RAISE(auto* lowercase_name_to_id, lowercase_name_to_id_.Get(*this));
101-
auto it = lowercase_name_to_id->find(StringUtils::ToLower(name));
102-
if (it == lowercase_name_to_id->end()) {
100+
ICEBERG_ASSIGN_OR_RAISE(auto lowercase_name_to_id, lowercase_name_to_id_.Get(*this));
101+
auto it = lowercase_name_to_id.get().find(StringUtils::ToLower(name));
102+
if (it == lowercase_name_to_id.get().end()) {
103103
return std::nullopt;
104104
}
105105
return FindFieldById(it->second);
@@ -136,9 +136,9 @@ Schema::InitLowerCaseNameToIdMap(const Schema& self) {
136136

137137
Result<std::optional<std::reference_wrapper<const SchemaField>>> Schema::FindFieldById(
138138
int32_t field_id) const {
139-
ICEBERG_ASSIGN_OR_RAISE(auto* id_to_field, id_to_field_.Get(*this));
140-
auto it = id_to_field->find(field_id);
141-
if (it == id_to_field->end()) {
139+
ICEBERG_ASSIGN_OR_RAISE(auto id_to_field, id_to_field_.Get(*this));
140+
auto it = id_to_field.get().find(field_id);
141+
if (it == id_to_field.get().end()) {
142142
return std::nullopt;
143143
}
144144
return it->second;

src/iceberg/type.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ std::string StructType::ToString() const {
5151
std::span<const SchemaField> StructType::fields() const { return fields_; }
5252
Result<std::optional<NestedType::SchemaFieldConstRef>> StructType::GetFieldById(
5353
int32_t field_id) const {
54-
ICEBERG_ASSIGN_OR_RAISE(auto* field_by_id, field_by_id_.Get(*this));
55-
auto it = field_by_id->find(field_id);
56-
if (it == field_by_id->end()) return std::nullopt;
54+
ICEBERG_ASSIGN_OR_RAISE(auto field_by_id, field_by_id_.Get(*this));
55+
auto it = field_by_id.get().find(field_id);
56+
if (it == field_by_id.get().end()) return std::nullopt;
5757
return it->second;
5858
}
5959
Result<std::optional<NestedType::SchemaFieldConstRef>> StructType::GetFieldByIndex(
@@ -66,17 +66,17 @@ Result<std::optional<NestedType::SchemaFieldConstRef>> StructType::GetFieldByInd
6666
Result<std::optional<NestedType::SchemaFieldConstRef>> StructType::GetFieldByName(
6767
std::string_view name, bool case_sensitive) const {
6868
if (case_sensitive) {
69-
ICEBERG_ASSIGN_OR_RAISE(auto* field_by_name, field_by_name_.Get(*this));
70-
auto it = field_by_name->find(name);
71-
if (it != field_by_name->end()) {
69+
ICEBERG_ASSIGN_OR_RAISE(auto field_by_name, field_by_name_.Get(*this));
70+
auto it = field_by_name.get().find(name);
71+
if (it != field_by_name.get().end()) {
7272
return it->second;
7373
}
7474
return std::nullopt;
7575
}
76-
ICEBERG_ASSIGN_OR_RAISE(auto* field_by_lowercase_name,
76+
ICEBERG_ASSIGN_OR_RAISE(auto field_by_lowercase_name,
7777
field_by_lowercase_name_.Get(*this));
78-
auto it = field_by_lowercase_name->find(StringUtils::ToLower(name));
79-
if (it != field_by_lowercase_name->end()) {
78+
auto it = field_by_lowercase_name.get().find(StringUtils::ToLower(name));
79+
if (it != field_by_lowercase_name.get().end()) {
8080
return it->second;
8181
}
8282
return std::nullopt;

src/iceberg/util/lazy.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
/// Transparent lazy initialization utility.
2424

2525
#include <concepts>
26+
#include <functional>
2627
#include <mutex>
2728

2829
#include "iceberg/result.h"
@@ -46,7 +47,7 @@ class Lazy {
4647
template <typename... Args>
4748
requires std::invocable<decltype(InitFunc), Args...> &&
4849
std::same_as<std::invoke_result_t<decltype(InitFunc), Args...>, Result<T>>
49-
Result<T*> Get(Args&&... args) const {
50+
Result<std::reference_wrapper<T>> Get(Args&&... args) const {
5051
Result<T> result;
5152
std::call_once(flag_, [&result, this, &args...]() {
5253
result = InitFunc(std::forward<Args>(args)...);
@@ -55,7 +56,7 @@ class Lazy {
5556
}
5657
});
5758
ICEBERG_RETURN_UNEXPECTED(result);
58-
return &value_;
59+
return std::ref(value_);
5960
}
6061

6162
private:

0 commit comments

Comments
 (0)