Skip to content

Commit

Permalink
Improve nullability check and annoations for nbest_generator.
Browse files Browse the repository at this point in the history
This CL improves the nullability check by using:
  * absl::Nonnull<> and absl::Nullable<>
  * Reference whenever possible

PiperOrigin-RevId: 648654106
  • Loading branch information
Noriyuki Takahashi authored and hiroyuki-komatsu committed Jul 2, 2024
1 parent 4f03239 commit 431ed8e
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 126 deletions.
5 changes: 4 additions & 1 deletion src/base/container/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ mozc_cc_library(
name = "freelist",
hdrs = ["freelist.h"],
visibility = ["//:__subpackages__"],
deps = ["//testing:friend_test"],
deps = [
"//testing:friend_test",
"@com_google_absl//absl/base:nullability",
],
)

mozc_cc_test(
Expand Down
5 changes: 3 additions & 2 deletions src/base/container/freelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <utility>
#include <vector>

#include "absl/base/nullability.h"
#include "testing/friend_test.h"

namespace mozc {
Expand Down Expand Up @@ -96,7 +97,7 @@ class FreeList {
next_in_chunk_ = std::numeric_limits<size_type>::max();
}

T* Alloc() {
absl::Nonnull<T*> Alloc() {
if (next_in_chunk_ >= chunk_size_) {
next_in_chunk_ = 0;
// Allocate the chunk with the allocate and delay the constructions until
Expand All @@ -105,7 +106,7 @@ class FreeList {
}

// Default construct T.
T* ptr = pool_.back() + next_in_chunk_++;
absl::Nonnull<T*> ptr = pool_.back() + next_in_chunk_++;
allocator_traits::construct(allocator_, ptr);
return ptr;
}
Expand Down
2 changes: 2 additions & 0 deletions src/converter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,11 @@ mozc_cc_library(
"//dictionary:suppression_dictionary",
"//prediction:suggestion_filter",
"//request:conversion_request",
"@com_google_absl//absl/base:nullability",
"@com_google_absl//absl/log",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:span",
],
)

Expand Down
Loading

0 comments on commit 431ed8e

Please sign in to comment.