mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
minor optimization: avoid opening a file twice when its full contents are read.
This commit is contained in:
@@ -33,7 +33,7 @@ File::~File()
|
||||
|
||||
FileData *File::read()
|
||||
{
|
||||
return read(getSize());
|
||||
return read(SIZE_ALL);
|
||||
}
|
||||
|
||||
FileData *File::read(int64 size)
|
||||
@@ -46,7 +46,9 @@ FileData *File::read(int64 size)
|
||||
int64 max = getSize();
|
||||
int64 cur = tell();
|
||||
|
||||
if (size < 0)
|
||||
if (size == SIZE_ALL)
|
||||
size = max;
|
||||
else if (size < 0)
|
||||
throw love::Exception("Invalid read size.");
|
||||
|
||||
// Clamping because the file offset may be in a weird position.
|
||||
|
||||
@@ -47,6 +47,8 @@ public:
|
||||
|
||||
static love::Type type;
|
||||
|
||||
static const int64 SIZE_ALL = -1;
|
||||
|
||||
/**
|
||||
* File open mode.
|
||||
**/
|
||||
|
||||
Reference in New Issue
Block a user