diff --git a/cmake/cmake_options_script.py b/cmake/cmake_options_script.py index 52e943e79..8d30604d5 100644 --- a/cmake/cmake_options_script.py +++ b/cmake/cmake_options_script.py @@ -32,13 +32,11 @@ cache_file = "%s/cached_options.txt" % (scriptpath) db = None if os.access(cache_file, os.R_OK) == 0: db = load_db(sys.argv[1]) - f = open(cache_file, "wb") - pickle.dump(db, f) - f.close() + with open(cache_file, "wb") as f: + pickle.dump(db, f) else: - f = open(cache_file) - db = pickle.load(f) - f.close() + with open(cache_file) as f: + db = pickle.load(f) if db and sys.argv[2] in db: for option in db[sys.argv[2]]: diff --git a/include/engine/datafacade/internal_datafacade.hpp b/include/engine/datafacade/internal_datafacade.hpp index b49bc463c..f671925a3 100644 --- a/include/engine/datafacade/internal_datafacade.hpp +++ b/include/engine/datafacade/internal_datafacade.hpp @@ -94,7 +94,6 @@ template class InternalDataFacade final : public BaseDataFacad util::SimpleLogger().Write(logWARNING) << timestamp_path << " not found"; } getline(timestamp_stream, m_timestamp); - timestamp_stream.close(); } if (m_timestamp.empty()) { @@ -144,7 +143,6 @@ template class InternalDataFacade final : public BaseDataFacad BOOST_ASSERT((std::abs(m_coordinate_list->at(i).lat) >> 30) == 0); BOOST_ASSERT((std::abs(m_coordinate_list->at(i).lon) >> 30) == 0); } - nodes_input_stream.close(); boost::filesystem::ifstream edges_input_stream(edges_file, std::ios::binary); unsigned number_of_edges = 0; @@ -172,8 +170,6 @@ template class InternalDataFacade final : public BaseDataFacad ++compressed; } } - - edges_input_stream.close(); } void LoadCoreInformation(const boost::filesystem::path &core_data_file) @@ -224,7 +220,6 @@ template class InternalDataFacade final : public BaseDataFacad geometry_stream.read((char *)&(m_geometry_list[0]), number_of_compressed_geometries * sizeof(extractor::CompressedEdgeContainer::CompressedEdge)); } - geometry_stream.close(); } void LoadRTree() @@ -250,7 +245,6 @@ template class InternalDataFacade final : public BaseDataFacad { util::SimpleLogger().Write(logWARNING) << "list of street names is empty"; } - name_stream.close(); } public: diff --git a/include/util/graph_loader.hpp b/include/util/graph_loader.hpp index 233d7aa70..5d060809e 100644 --- a/include/util/graph_loader.hpp +++ b/include/util/graph_loader.hpp @@ -194,7 +194,6 @@ unsigned readHSGRFromStream(const boost::filesystem::path &hsgr_file, hsgr_input_stream.read(reinterpret_cast(&edge_list[0]), number_of_edges * sizeof(EdgeT)); } - hsgr_input_stream.close(); return number_of_nodes; } diff --git a/include/util/static_rtree.hpp b/include/util/static_rtree.hpp index 94b8ea360..f630fd671 100644 --- a/include/util/static_rtree.hpp +++ b/include/util/static_rtree.hpp @@ -191,9 +191,6 @@ class StaticRTree processed_objects_count += current_leaf.object_count; } - // close leaf file - leaf_node_file.close(); - std::uint32_t processing_level = 0; while (1 < tree_nodes_in_level.size()) { @@ -257,8 +254,6 @@ class StaticRTree BOOST_ASSERT_MSG(0 < size_of_tree, "tree empty"); tree_node_file.write((char *)&size_of_tree, sizeof(std::uint32_t)); tree_node_file.write((char *)&m_search_tree[0], sizeof(TreeNode) * size_of_tree); - // close tree node file. - tree_node_file.close(); } explicit StaticRTree(const boost::filesystem::path &node_file, @@ -287,7 +282,7 @@ class StaticRTree { tree_node_file.read((char *)&m_search_tree[0], sizeof(TreeNode) * tree_size); } - tree_node_file.close(); + // open leaf node file and store thread specific pointer if (!boost::filesystem::exists(leaf_file)) { diff --git a/src/benchmarks/static_rtree.cpp b/src/benchmarks/static_rtree.cpp index 79432f7de..745fad3df 100644 --- a/src/benchmarks/static_rtree.cpp +++ b/src/benchmarks/static_rtree.cpp @@ -45,7 +45,6 @@ FixedPointCoordinateListPtr loadCoordinates(const boost::filesystem::path &nodes BOOST_ASSERT((std::abs(coords->at(i).lat) >> 30) == 0); BOOST_ASSERT((std::abs(coords->at(i).lon) >> 30) == 0); } - nodes_input_stream.close(); return coords; } diff --git a/src/contractor/contractor.cpp b/src/contractor/contractor.cpp index a3831ce3d..3cfcdef03 100644 --- a/src/contractor/contractor.cpp +++ b/src/contractor/contractor.cpp @@ -212,7 +212,6 @@ std::size_t Contractor::LoadEdgeExpandedGraph( // Load all the query nodes into a vector nodes_input_stream.read(reinterpret_cast(&(internal_to_external_node_map[0])), number_of_nodes * sizeof(extractor::QueryNode)); - nodes_input_stream.close(); } std::vector m_geometry_indices; @@ -246,7 +245,6 @@ std::size_t Contractor::LoadEdgeExpandedGraph( geometry_stream.read((char *)&(m_geometry_list[0]), number_of_compressed_geometries * sizeof(extractor::CompressedEdgeContainer::CompressedEdge)); } - geometry_stream.close(); } // Now, we iterate over all the segments stored in the StaticRTree, updating @@ -256,7 +254,6 @@ std::size_t Contractor::LoadEdgeExpandedGraph( using LeafNode = util::StaticRTree::LeafNode; - // Open file for reading *and* writing std::ifstream leaf_node_file(rtree_leaf_filename, std::ios::binary | std::ios::in); if (!leaf_node_file) { @@ -336,8 +333,6 @@ std::size_t Contractor::LoadEdgeExpandedGraph( m_element_count -= current_node.object_count; } - leaf_node_file.close(); - } // Now save out the updated compressed geometries @@ -353,7 +348,6 @@ std::size_t Contractor::LoadEdgeExpandedGraph( geometry_stream.write(reinterpret_cast(&(m_geometry_indices[0])), number_of_indices * sizeof(unsigned)); geometry_stream.write(reinterpret_cast(&number_of_compressed_geometries), sizeof(unsigned)); geometry_stream.write(reinterpret_cast(&(m_geometry_list[0])), number_of_compressed_geometries * sizeof(extractor::CompressedEdgeContainer::CompressedEdge)); - geometry_stream.close(); } diff --git a/src/extractor/compressed_edge_container.cpp b/src/extractor/compressed_edge_container.cpp index 51d44c23f..d6b6cc0b2 100644 --- a/src/extractor/compressed_edge_container.cpp +++ b/src/extractor/compressed_edge_container.cpp @@ -84,8 +84,6 @@ void CompressedEdgeContainer::SerializeInternalVector(const std::string &path) c } } BOOST_ASSERT(control_sum == prefix_sum_of_list_indices); - // all done, let's close the resource - geometry_out_stream.close(); } // Adds info for a compressed edge to the container. edge_id_2 diff --git a/src/extractor/edge_based_graph_factory.cpp b/src/extractor/edge_based_graph_factory.cpp index 3b8eb96a7..240ffbbce 100644 --- a/src/extractor/edge_based_graph_factory.cpp +++ b/src/extractor/edge_based_graph_factory.cpp @@ -476,7 +476,6 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( edge_data_file.seekp(std::ios::beg); edge_data_file.write((char *)&original_edges_counter, sizeof(unsigned)); - edge_data_file.close(); util::SimpleLogger().Write() << "Generated " << m_edge_based_node_list.size() << " edge based nodes"; diff --git a/src/extractor/extraction_containers.cpp b/src/extractor/extraction_containers.cpp index 1f8d8e94a..14cf391ed 100644 --- a/src/extractor/extraction_containers.cpp +++ b/src/extractor/extraction_containers.cpp @@ -90,8 +90,6 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name, PrepareEdges(segment_state); WriteEdges(file_out_stream); - file_out_stream.close(); - PrepareRestrictions(); WriteRestrictions(restrictions_file_name); @@ -139,7 +137,6 @@ void ExtractionContainers::WriteNames(const std::string &names_file_name) const name_file_stream.write(write_buffer, buffer_len); - name_file_stream.close(); TIMER_STOP(write_name_index); std::cout << "ok, after " << TIMER_SEC(write_name_index) << "s" << std::endl; } @@ -586,7 +583,6 @@ void ExtractionContainers::WriteRestrictions(const std::string &path) const } restrictions_out_stream.seekp(count_position); restrictions_out_stream.write((char *)&written_restriction_count, sizeof(unsigned)); - restrictions_out_stream.close(); util::SimpleLogger().Write() << "usable restrictions: " << written_restriction_count; } diff --git a/src/extractor/extractor.cpp b/src/extractor/extractor.cpp index 500d2e1e0..10f0fa6f4 100644 --- a/src/extractor/extractor.cpp +++ b/src/extractor/extractor.cpp @@ -134,7 +134,6 @@ int Extractor::run() boost::filesystem::ofstream timestamp_out(config.timestamp_file_name); timestamp_out.write(timestamp.c_str(), timestamp.length()); - timestamp_out.close(); // initialize vectors holding parsed objects tbb::concurrent_vector> resulting_nodes; @@ -558,7 +557,6 @@ void Extractor::WriteNodeMapping(const std::vector &internal_to_exter node_stream.write((char *)internal_to_external_node_map.data(), size_of_mapping * sizeof(QueryNode)); } - node_stream.close(); } /** @@ -630,7 +628,6 @@ void Extractor::WriteEdgeBasedGraph( util::SimpleLogger().Write() << "ok, after " << TIMER_SEC(write_edges) << "s" << std::endl; util::SimpleLogger().Write() << "Processed " << number_of_used_edges << " edges"; - file_out_stream.close(); } } } diff --git a/src/storage/storage.cpp b/src/storage/storage.cpp index 0bcd1a094..a9588b0b2 100644 --- a/src/storage/storage.cpp +++ b/src/storage/storage.cpp @@ -288,7 +288,6 @@ int Storage::Run() else { getline(timestamp_stream, m_timestamp); - timestamp_stream.close(); } } if (m_timestamp.empty()) diff --git a/src/tools/io-benchmark.cpp b/src/tools/io-benchmark.cpp index 0ccf97ece..37cccd3b1 100644 --- a/src/tools/io-benchmark.cpp +++ b/src/tools/io-benchmark.cpp @@ -233,7 +233,6 @@ int main(int argc, char *argv[]) try { random_csv << i << ", " << timing_results_raw_random[i] << std::endl; } - random_csv.close(); osrm::tools::runStatistics(timing_results_raw_random, stats); osrm::util::SimpleLogger().Write() << "raw random I/O: " << std::setprecision(5) @@ -305,7 +304,6 @@ int main(int argc, char *argv[]) try { seq_csv << i << ", " << timing_results_raw_seq[i] << std::endl; } - seq_csv.close(); osrm::tools::runStatistics(timing_results_raw_seq, stats); osrm::util::SimpleLogger().Write() << "raw sequential I/O: " << std::setprecision(5) << std::fixed << "min: " << stats.min << "ms, " diff --git a/unit_tests/util/static_rtree.cpp b/unit_tests/util/static_rtree.cpp index 0dbf8cc36..bec4527ef 100644 --- a/unit_tests/util/static_rtree.cpp +++ b/unit_tests/util/static_rtree.cpp @@ -261,7 +261,6 @@ void build_rtree(const std::string &prefix, const auto num_nodes = static_cast(fixture->nodes.size()); node_stream.write((char *)&num_nodes, sizeof(unsigned)); node_stream.write((char *)&(fixture->nodes[0]), num_nodes * sizeof(extractor::QueryNode)); - node_stream.close(); RTreeT r(fixture->edges, nodes_path, leaves_path, fixture->nodes); }