declared char * buf global, so it can be initialized in copy_blocks().

* include/GParted_Core.h,
  src/GParted_Core.cc: declared char * buf global, so it can be
  initialized in copy_blocks(). This is a lot more efficient than
  initializing it on every copy_block()
This commit is contained in:
Bart Hakvoort 2006-09-08 09:33:02 +00:00
parent c5853ab734
commit 59fe25882a
3 changed files with 55 additions and 46 deletions

View File

@ -1,3 +1,10 @@
2006-09-08 Bart Hakvoort <hakvoort@cvs.gnome.org>
* include/GParted_Core.h,
src/GParted_Core.cc: declared char * buf global, so it can be
initialized in copy_blocks(). This is a lot more efficient than
initializing it on every copy_block()
2006-09-08 Bart Hakvoort <hakvoort@cvs.gnome.org> 2006-09-08 Bart Hakvoort <hakvoort@cvs.gnome.org>
* src/GParted_Core.cc: skip resize/move of partition/filesystem if * src/GParted_Core.cc: skip resize/move of partition/filesystem if

View File

@ -171,6 +171,8 @@ private:
PedDevice *lp_device ; PedDevice *lp_device ;
PedDisk *lp_disk ; PedDisk *lp_disk ;
PedPartition *lp_partition ; PedPartition *lp_partition ;
char * buf ;
}; };
} //GParted } //GParted

View File

@ -668,7 +668,7 @@ GParted::FILESYSTEM GParted_Core::get_filesystem()
ped_geometry_read( & lp_partition ->geom, buf, 128, 1 ) ; ped_geometry_read( & lp_partition ->geom, buf, 128, 1 ) ;
ped_device_close( lp_device ); ped_device_close( lp_device );
if ( static_cast<Glib::ustring>( buf ) == "ReIsEr4" ) if ( Glib::ustring( buf ) == "ReIsEr4" )
return GParted::FS_REISER4 ; return GParted::FS_REISER4 ;
//no filesystem found.... //no filesystem found....
@ -1726,47 +1726,55 @@ bool GParted_Core::copy_blocks( const Glib::ustring & src_device,
if ( lp_device_src && lp_device_dst && ped_device_open( lp_device_src ) && ped_device_open( lp_device_dst ) ) if ( lp_device_src && lp_device_dst && ped_device_open( lp_device_src ) && ped_device_open( lp_device_dst ) )
{ {
succes = true ;
ped_device_sync( lp_device_dst ) ; ped_device_sync( lp_device_dst ) ;
Glib::ustring error_message ; Glib::ustring error_message ;
if ( done != 0 ) buf = static_cast<char *>( malloc( std::abs( blocksize ) * 512 ) ) ;
succes = copy_block( lp_device_src, if ( buf )
lp_device_dst,
src_start,
dst_start,
done,
error_message,
readonly ) ;
//add an empty sub which we will constantly update in the loop
operationdetail .get_last_child() .add_child( OperationDetail( "", STATUS_NONE ) ) ;
Glib::Timer timer_progress_timeout, timer_total ;
while( succes && std::abs( done ) < length )
{ {
succes = copy_block( lp_device_src, succes = true ;
lp_device_dst, if ( done != 0 )
src_start +done, succes = copy_block( lp_device_src,
dst_start +done, lp_device_dst,
blocksize, src_start,
error_message, dst_start,
readonly ) ; done,
if ( succes ) error_message,
done += blocksize ; readonly ) ;
if ( timer_progress_timeout .elapsed() >= 0.5 ) //add an empty sub which we will constantly update in the loop
operationdetail .get_last_child() .add_child( OperationDetail( "", STATUS_NONE ) ) ;
Glib::Timer timer_progress_timeout, timer_total ;
while( succes && std::abs( done ) < length )
{ {
set_progress_info( length, succes = copy_block( lp_device_src,
std::abs( done + blocksize ), lp_device_dst,
timer_total, src_start +done,
operationdetail .get_last_child() .get_last_child(), dst_start +done,
readonly ) ; blocksize,
error_message,
timer_progress_timeout .reset() ; readonly ) ;
if ( succes )
done += blocksize ;
if ( timer_progress_timeout .elapsed() >= 0.5 )
{
set_progress_info( length,
std::abs( done + blocksize ),
timer_total,
operationdetail .get_last_child() .get_last_child(),
readonly ) ;
timer_progress_timeout .reset() ;
}
} }
free( buf ) ;
} }
else
error_message = Glib::strerror( errno ) ;
//reset fraction to -1 to make room for a new one (or a pulsebar) //reset fraction to -1 to make room for a new one (or a pulsebar)
operationdetail .get_last_child() .get_last_child() .fraction = -1 ; operationdetail .get_last_child() .get_last_child() .fraction = -1 ;
@ -1813,23 +1821,15 @@ bool GParted_Core::copy_block( PedDevice * lp_device_src,
if ( blocksize != 0 ) if ( blocksize != 0 )
{ {
char * buf = static_cast<char *>( malloc( blocksize * 512 ) ) ;//FIXME: declare buf global and initialize in copy_blocks() if ( ped_device_read( lp_device_src, buf, offset_src, blocksize ) )
if ( buf )
{ {
if ( ped_device_read( lp_device_src, buf, offset_src, blocksize ) ) if ( readonly || ped_device_write( lp_device_dst, buf, offset_dst, blocksize ) )
{ succes = true ;
if ( readonly || ped_device_write( lp_device_dst, buf, offset_dst, blocksize ) )
succes = true ;
else
error_message = String::ucompose( _("Error while writing block at sector %1"), offset_dst ) ;
}
else else
error_message = String::ucompose( _("Error while reading block at sector %1"), offset_src ) ; error_message = String::ucompose( _("Error while writing block at sector %1"), offset_dst ) ;
free( buf ) ;
} }
else else
error_message = Glib::strerror( errno ) ; error_message = String::ucompose( _("Error while reading block at sector %1"), offset_src ) ;
} }
return succes ; return succes ;