mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 04:24:09 +00:00
Merge pull request #1196 from shenlebantongying/faster_img_loading
fix: avoid QFile::readall when loading resources
This commit is contained in:
commit
337fe7dcf0
|
@ -36,9 +36,9 @@ bool tryPossibleZipName( std::string const & name, std::string & copyTo )
|
||||||
void loadFromFile( std::string const & filename, std::vector< char > & data )
|
void loadFromFile( std::string const & filename, std::vector< char > & data )
|
||||||
{
|
{
|
||||||
File::Class f( filename, "rb" );
|
File::Class f( filename, "rb" );
|
||||||
QByteArray byteArray{ f.readall() };
|
auto size = f.file().size(); // QFile::size() obtains size via statx on Linux
|
||||||
data.reserve( byteArray.size() );
|
data.resize( size );
|
||||||
data = std::vector< char >( byteArray.cbegin(), byteArray.cend() );
|
f.read( data.data(), size );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Class::open( char const * mode )
|
void Class::open( char const * mode )
|
||||||
|
@ -82,10 +82,9 @@ Class::Class( std::string_view filename, char const * mode )
|
||||||
|
|
||||||
void Class::read( void * buf, qint64 size )
|
void Class::read( void * buf, qint64 size )
|
||||||
{
|
{
|
||||||
qint64 result = f.read( static_cast< char * >( buf ), size );
|
if ( f.read( static_cast< char * >( buf ), size ) != size ) {
|
||||||
|
|
||||||
if ( result != size )
|
|
||||||
throw exReadError();
|
throw exReadError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Class::readRecords( void * buf, qint64 size, qint64 count )
|
size_t Class::readRecords( void * buf, qint64 size, qint64 count )
|
||||||
|
|
|
@ -13,7 +13,8 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
|
||||||
/// A simple wrapper over QFile with some convenient GD specific functions
|
/// A wrapper over QFile with some GD specific functions
|
||||||
|
/// and exception throwing which are required for older coded to work correctly
|
||||||
/// Consider the wrapped QFile as private implementation in the `Pimpl Idiom`
|
/// Consider the wrapped QFile as private implementation in the `Pimpl Idiom`
|
||||||
///
|
///
|
||||||
/// Note: this is used *only* in code related to `Dictionary::CLass` to manage dict files.
|
/// Note: this is used *only* in code related to `Dictionary::CLass` to manage dict files.
|
||||||
|
|
|
@ -5,18 +5,9 @@ html {
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
font-family:
|
font-family: -apple-system, BlinkMacSystemFont, Tahoma, Verdana,
|
||||||
-apple-system,
|
"Lucida Sans Unicode", "Palatino Linotype", "Arial Unicode MS", "Segoe UI",
|
||||||
BlinkMacSystemFont,
|
Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
|
||||||
Tahoma, Verdana, "Lucida Sans Unicode","Palatino Linotype", "Arial Unicode MS",
|
|
||||||
"Segoe UI",
|
|
||||||
Roboto,
|
|
||||||
Oxygen,
|
|
||||||
Ubuntu,
|
|
||||||
Cantarell,
|
|
||||||
"Open Sans",
|
|
||||||
"Helvetica Neue",
|
|
||||||
sans-serif;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
h1,
|
h1,
|
||||||
|
|
Loading…
Reference in a new issue