Skip to content

Commit

Permalink
Addressed some VS code analysis warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Nov 14, 2024
1 parent 63b01a2 commit 5baaf4d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
23 changes: 13 additions & 10 deletions include/jsoncons/config/compiler_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,6 @@

// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54577

#if defined(__clang__)
# define JSONCONS_FALLTHROUGH [[clang::fallthrough]]
#elif defined(__GNUC__) && ((__GNUC__ >= 7))
# define JSONCONS_FALLTHROUGH __attribute__((fallthrough))
#elif defined (__GNUC__)
# define JSONCONS_FALLTHROUGH // FALLTHRU
#else
# define JSONCONS_FALLTHROUGH
#endif

#if defined(__GNUC__) || defined(__clang__)
#define JSONCONS_LIKELY(x) __builtin_expect(!!(x), 1)
#define JSONCONS_UNLIKELY(x) __builtin_expect(!!(x), 0)
Expand Down Expand Up @@ -414,4 +404,17 @@ namespace jsoncons {
JSONCONS_STR( 0 ))); }
#endif // _DEBUG

#if defined(JSONCONS_HAS_2017)
# define JSONCONS_FALLTHROUGH [[fallthrough]]
#elif defined(__clang__)
# define JSONCONS_FALLTHROUGH [[clang::fallthrough]]
#elif defined(__GNUC__) && ((__GNUC__ >= 7))
# define JSONCONS_FALLTHROUGH __attribute__((fallthrough))
#elif defined (__GNUC__)
# define JSONCONS_FALLTHROUGH // FALLTHRU
#else
# define JSONCONS_FALLTHROUGH
#endif


#endif // JSONCONS_COMPILER_SUPPORT_HPP
23 changes: 11 additions & 12 deletions include/jsoncons/json_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,23 +518,20 @@ namespace jsoncons {

void uninitialized_init(index_key_value<Json>* items, std::size_t count)
{
auto first = items;
if (count > 0)
{
members_.reserve(count);

auto last = first + count;

std::sort(first, last, compare);
members_.emplace_back(key_type(first->name.c_str(), first->name.size(), get_allocator()), std::move(first->value));
auto prev_it = first;
for (auto it = first+1; it != last; ++it)
std::sort(items, items+count, compare);
members_.emplace_back(key_type(items[0].name.data(), items[0].name.size(), get_allocator()), std::move(items[0].value));

for (std::size_t i = 1; i < count; ++i)
{
if (it->name != prev_it->name)
auto& item = items[i];
if (item.name != items[i-1].name)
{
members_.emplace_back(key_type(it->name.c_str(), it->name.size(), get_allocator()), std::move(it->value));
members_.emplace_back(key_type(item.name.data(), item.name.size(), get_allocator()), std::move(item.value));
}
++prev_it;
}
}
}
Expand Down Expand Up @@ -1318,9 +1315,11 @@ namespace jsoncons {
std::sort(first, last, compare2);

members_.reserve(count);
for (auto it = first; it != last; ++it)

//for (auto it = first; it != last; ++it)
for (std::size_t i = 0; i < count; ++i)
{
members_.emplace_back(std::move(it->name), std::move(it->value));
members_.emplace_back(std::move(first[i].name), std::move(first[i].value));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion include/jsoncons/utility/heap_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace utility {
Extra extra() const { return this->extra_; }

heap_string(Extra extra, const Allocator& alloc)
: heap_string_base<Extra,Allocator>(extra, alloc), p_(nullptr), length_(0), offset_(0)
: heap_string_base<Extra,Allocator>(extra, alloc), p_(nullptr), length_(0), offset_(0), align_pad_(0)
{
}

Expand Down
5 changes: 3 additions & 2 deletions include/jsoncons_ext/jsonschema/common/validator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ namespace jsonschema {
}
void merge(std::unordered_set<std::string>&& properties)
{
for (auto&& name : properties)
auto end = std::make_move_iterator(properties.end());
for (auto it = std::make_move_iterator(properties.begin()); it != end; ++it)
{
evaluated_properties.insert(std::move(name));
evaluated_properties.insert(*it);
}
}
void merge(const range_collection& ranges)
Expand Down

0 comments on commit 5baaf4d

Please sign in to comment.