Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2023.
[simgrid.git] / src / smpi / internals / smpi_shared.cpp
index 2c120fb..a34d667 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -126,9 +126,8 @@ static void *smpi_shared_malloc_local(size_t size, const char *file, int line)
 {
   void* mem;
   smpi_source_location loc(file, line);
-  auto res = allocs.insert(std::make_pair(loc, shared_data_t()));
-  auto data = res.first;
-  if (res.second) {
+  auto [data, inserted] = allocs.try_emplace(loc);
+  if (inserted) {
     // The new element was inserted.
     int fd             = smpi_temp_shm_get();
     data->second.fd    = fd;
@@ -400,9 +399,9 @@ std::vector<std::pair<size_t, size_t>> shift_and_frame_private_blocks(const std:
                                                                       size_t offset, size_t buff_size)
 {
   std::vector<std::pair<size_t, size_t>> result;
-  for (auto const& block : vec) {
-    auto new_block = std::make_pair(std::min(std::max((size_t)0, block.first - offset), buff_size),
-                                    std::min(std::max((size_t)0, block.second - offset), buff_size));
+  for (auto const& [block_begin, block_end] : vec) {
+    auto new_block = std::make_pair(std::clamp(block_begin - offset, (size_t)0, buff_size),
+                                    std::clamp(block_end - offset, (size_t)0, buff_size));
     if (new_block.second > 0 && new_block.first < buff_size)
       result.push_back(new_block);
   }