Skip to content

Commit

Permalink
Merge pull request #1065 from alex85k/patch-skip-zero-rw
Browse files Browse the repository at this point in the history
skip zero bytes reading or wrtiting
  • Loading branch information
DennisOSRM committed Jun 6, 2014
2 parents a32116d + b6787b0 commit 05bcfd2
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 18 deletions.
5 changes: 4 additions & 1 deletion DataStructures/StaticRTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,10 @@ class StaticRTree
tree_node_file.read((char *)&tree_size, sizeof(uint32_t));

m_search_tree.resize(tree_size);
tree_node_file.read((char *)&m_search_tree[0], sizeof(TreeNode) * tree_size);
if (tree_size > 0)
{
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))
Expand Down
10 changes: 8 additions & 2 deletions Server/DataStructures/InternalDataFacade.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,22 @@ template <class EdgeDataT> class InternalDataFacade : public BaseDataFacade<Edge
geometry_stream.read((char *)&number_of_indices, sizeof(unsigned));

m_geometry_indices.resize(number_of_indices);
geometry_stream.read((char *)&(m_geometry_indices[0]),
if (number_of_indices > 0)
{
geometry_stream.read((char *)&(m_geometry_indices[0]),
number_of_indices * sizeof(unsigned));
}

geometry_stream.read((char *)&number_of_compressed_geometries, sizeof(unsigned));

BOOST_ASSERT(m_geometry_indices.back() == number_of_compressed_geometries);
m_geometry_list.resize(number_of_compressed_geometries);

geometry_stream.read((char *)&(m_geometry_list[0]),
if (number_of_compressed_geometries > 0)
{
geometry_stream.read((char *)&(m_geometry_list[0]),
number_of_compressed_geometries * sizeof(unsigned));
}
geometry_stream.close();
}

Expand Down
7 changes: 5 additions & 2 deletions Tools/components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ int main(int argc, char *argv[])
restriction_ifstream.read((char *)&usable_restriction_count, sizeof(uint32_t));
restrictions_vector.resize(usable_restriction_count);

restriction_ifstream.read((char *)&(restrictions_vector[0]),
usable_restriction_count * sizeof(TurnRestriction));
if (usable_restriction_count>0)
{
restriction_ifstream.read((char *)&(restrictions_vector[0]),
usable_restriction_count * sizeof(TurnRestriction));
}
restriction_ifstream.close();

std::ifstream input_stream;
Expand Down
5 changes: 4 additions & 1 deletion Util/GraphLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,10 @@ unsigned readHSGRFromStream(const boost::filesystem::path &hsgr_file,
hsgr_input_stream.read((char *)&(node_list[0]), number_of_nodes * sizeof(NodeT));

edge_list.resize(number_of_edges);
hsgr_input_stream.read((char *)&(edge_list[0]), number_of_edges * sizeof(EdgeT));
if (number_of_edges > 0)
{
hsgr_input_stream.read((char *)&(edge_list[0]), number_of_edges * sizeof(EdgeT));
}
hsgr_input_stream.close();

return number_of_nodes;
Expand Down
37 changes: 28 additions & 9 deletions datastore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,17 @@ int main(const int argc, const char *argv[])
// Loading street names
unsigned *name_index_ptr =
(unsigned *)(shared_memory_ptr + shared_layout_ptr->GetNameIndexOffset());

name_stream.read((char *)name_index_ptr,
if (shared_layout_ptr->name_index_list_size > 0)
{
name_stream.read((char *)name_index_ptr,
shared_layout_ptr->name_index_list_size * sizeof(unsigned));
}

char *name_char_ptr = shared_memory_ptr + shared_layout_ptr->GetNameListOffset();
name_stream.read(name_char_ptr, shared_layout_ptr->name_char_list_size * sizeof(char));
if (shared_layout_ptr->name_char_list_size > 0)
{
name_stream.read(name_char_ptr, shared_layout_ptr->name_char_list_size * sizeof(char));
}
name_stream.close();

// load original edge information
Expand Down Expand Up @@ -387,19 +392,24 @@ int main(const int argc, const char *argv[])
geometry_input_stream.seekg(0, geometry_input_stream.beg);
geometry_input_stream.read((char *)&temporary_value, sizeof(unsigned));
BOOST_ASSERT(temporary_value == shared_layout_ptr->geometries_index_list_size);

geometry_input_stream.read((char *)geometries_index_ptr,
if (shared_layout_ptr->geometries_index_list_size > 0)
{
geometry_input_stream.read((char *)geometries_index_ptr,
shared_layout_ptr->geometries_index_list_size *
sizeof(unsigned));
}

unsigned *geometries_list_ptr =
(unsigned *)(shared_memory_ptr + shared_layout_ptr->GetGeometryListOffset());

geometry_input_stream.read((char *)&temporary_value, sizeof(unsigned));
BOOST_ASSERT(temporary_value == shared_layout_ptr->geometries_list_size);

geometry_input_stream.read((char *)geometries_list_ptr,
if (shared_layout_ptr->geometries_list_size > 0)
{
geometry_input_stream.read((char *)geometries_list_ptr,
shared_layout_ptr->geometries_list_size * sizeof(unsigned));
}

// Loading list of coordinates
FixedPointCoordinate *coordinates_ptr =
Expand All @@ -423,24 +433,33 @@ int main(const int argc, const char *argv[])
char *rtree_ptr =
static_cast<char *>(shared_memory_ptr + shared_layout_ptr->GetRSearchTreeOffset());

tree_node_file.read(rtree_ptr, sizeof(RTreeNode) * tree_size);
if (tree_size > 0)
{
tree_node_file.read(rtree_ptr, sizeof(RTreeNode) * tree_size);
}
tree_node_file.close();

// load the nodes of the search graph
QueryGraph::NodeArrayEntry *graph_node_list_ptr =
(QueryGraph::NodeArrayEntry *)(shared_memory_ptr +
shared_layout_ptr->GetGraphNodeListOffset());
hsgr_input_stream.read((char *)graph_node_list_ptr,
if (shared_layout_ptr->graph_node_list_size > 0)
{
hsgr_input_stream.read((char *)graph_node_list_ptr,
shared_layout_ptr->graph_node_list_size *
sizeof(QueryGraph::NodeArrayEntry));
}

// load the edges of the search graph
QueryGraph::EdgeArrayEntry *graph_edge_list_ptr =
(QueryGraph::EdgeArrayEntry *)(shared_memory_ptr +
shared_layout_ptr->GetGraphEdgeListOffset());
hsgr_input_stream.read((char *)graph_edge_list_ptr,
if (shared_layout_ptr->graph_edge_list_size > 0)
{
hsgr_input_stream.read((char *)graph_edge_list_ptr,
shared_layout_ptr->graph_edge_list_size *
sizeof(QueryGraph::EdgeArrayEntry));
}
hsgr_input_stream.close();

// acquire lock
Expand Down
15 changes: 12 additions & 3 deletions prepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,11 @@ int main(int argc, char *argv[])

restriction_stream.read((char *)&number_of_usable_restrictions, sizeof(unsigned));
restriction_list.resize(number_of_usable_restrictions);
restriction_stream.read((char *)&(restriction_list[0]),
if (number_of_usable_restrictions > 0)
{
restriction_stream.read((char *)&(restriction_list[0]),
number_of_usable_restrictions * sizeof(TurnRestriction));
}
restriction_stream.close();

boost::filesystem::ifstream in;
Expand Down Expand Up @@ -347,8 +350,11 @@ int main(int argc, char *argv[])
boost::filesystem::ofstream node_stream(node_filename, std::ios::binary);
const unsigned size_of_mapping = internal_to_external_node_map.size();
node_stream.write((char *)&size_of_mapping, sizeof(unsigned));
node_stream.write((char *)&(internal_to_external_node_map[0]),
if (size_of_mapping > 0)
{
node_stream.write((char *)&(internal_to_external_node_map[0]),
size_of_mapping * sizeof(NodeInfo));
}
node_stream.close();
internal_to_external_node_map.clear();
internal_to_external_node_map.shrink_to_fit();
Expand Down Expand Up @@ -429,8 +435,11 @@ int main(int argc, char *argv[])
// serialize number of edges
hsgr_output_stream.write((char *)&contracted_edge_count, sizeof(unsigned));
// serialize all nodes
hsgr_output_stream.write((char *)&node_array[0],
if (node_array_size > 0)
{
hsgr_output_stream.write((char *)&node_array[0],
sizeof(StaticGraph<EdgeData>::NodeArrayEntry) * node_array_size);
}
// serialize all edges

SimpleLogger().Write() << "Building edge array";
Expand Down

0 comments on commit 05bcfd2

Please sign in to comment.