Permalink
Browse files

use mmap for checksum

  • Loading branch information...
1 parent ce24557 commit 7cc4984932dad019a2ff11f8b32a1745445c9850 @nestal nestal committed Jul 16, 2012
Showing with 11 additions and 8 deletions.
  1. +2 −2 libgrive/src/drive/Drive.cc
  2. +9 −6 libgrive/src/util/Crypt.cc
@@ -140,7 +140,7 @@ void Drive::DetectChanges()
Log( "Reading remote server file list", log::info ) ;
Feed feed ;
- feed.EnableLog( "/tmp/file", ".xml" ) ;
+// feed.EnableLog( "/tmp/file", ".xml" ) ;
feed.Start( &http, m_http_hdr, feed_base + "?showfolders=true&showroot=true" ) ;
m_resume_link = feed.Root()["link"].
@@ -159,7 +159,7 @@ void Drive::DetectChanges()
{
Log( "Detecting changes from last sync", log::info ) ;
Feed changes ;
- feed.EnableLog( "/tmp/changes", ".xml" ) ;
+// feed.EnableLog( "/tmp/changes", ".xml" ) ;
feed.Start( &http, m_http_hdr, ChangesFeed(prev_stamp+1) ) ;
std::for_each(
View
@@ -21,6 +21,7 @@
#include "StdioFile.hh"
#include "Exception.hh"
+#include "MemMap.hh"
#include <iomanip>
#include <sstream>
@@ -31,7 +32,8 @@
namespace gr { namespace crypt {
-const std::size_t read_size = 8 * 1024 ;
+// map 4MB of data at a time
+const u64_t read_size = 1024 * 4096 ;
struct MD5::Impl
{
@@ -85,13 +87,14 @@ std::string MD5::Get( const fs::path& file )
std::string MD5::Get( StdioFile& file )
{
- char buf[read_size] ;
-
MD5 crypt ;
- std::size_t count = 0 ;
- while ( (count = file.Read( buf, sizeof(buf) )) > 0 )
- crypt.Write( buf, count ) ;
+ u64_t size = file.Size() ;
+ for ( u64_t i = 0 ; i < size ; i += read_size )
+ {
+ MemMap map( file, i, static_cast<std::size_t>(std::min(read_size, size-i)) ) ;
+ crypt.Write( map.Addr(), map.Length() ) ;
+ }
return crypt.Get() ;
}

0 comments on commit 7cc4984

Please sign in to comment.