mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 16:59:44 +00:00
RegionLoader: Stop unnecessarily writing location header on close
Any time a region is modified, the location header is written anyway, so this is entirely unnecessary.
This commit is contained in:
parent
d080d3bae0
commit
1e0f1e5b1a
@ -148,7 +148,7 @@ abstract class RegionLevelProvider extends BaseLevelProvider{
|
|||||||
$logger = \GlobalLogger::get();
|
$logger = \GlobalLogger::get();
|
||||||
$logger->error("Corrupted region file detected: " . $e->getMessage());
|
$logger->error("Corrupted region file detected: " . $e->getMessage());
|
||||||
|
|
||||||
$region->close(false); //Do not write anything to the file
|
$region->close(); //Do not write anything to the file
|
||||||
|
|
||||||
$backupPath = $path . ".bak." . time();
|
$backupPath = $path . ".bak." . time();
|
||||||
rename($path, $backupPath);
|
rename($path, $backupPath);
|
||||||
|
@ -40,7 +40,6 @@ use function fwrite;
|
|||||||
use function is_resource;
|
use function is_resource;
|
||||||
use function max;
|
use function max;
|
||||||
use function ord;
|
use function ord;
|
||||||
use function pack;
|
|
||||||
use function str_pad;
|
use function str_pad;
|
||||||
use function stream_set_read_buffer;
|
use function stream_set_read_buffer;
|
||||||
use function stream_set_write_buffer;
|
use function stream_set_write_buffer;
|
||||||
@ -102,7 +101,6 @@ class RegionLoader{
|
|||||||
|
|
||||||
public function __destruct(){
|
public function __destruct(){
|
||||||
if(is_resource($this->filePointer)){
|
if(is_resource($this->filePointer)){
|
||||||
$this->writeLocationTable();
|
|
||||||
fclose($this->filePointer);
|
fclose($this->filePointer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -244,16 +242,10 @@ class RegionLoader{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the region header and closes the file
|
* Closes the file
|
||||||
*
|
|
||||||
* @param bool $writeHeader
|
|
||||||
*/
|
*/
|
||||||
public function close(bool $writeHeader = true) : void{
|
public function close() : void{
|
||||||
if(is_resource($this->filePointer)){
|
if(is_resource($this->filePointer)){
|
||||||
if($writeHeader){
|
|
||||||
$this->writeLocationTable();
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose($this->filePointer);
|
fclose($this->filePointer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -320,19 +312,6 @@ class RegionLoader{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function writeLocationTable() : void{
|
|
||||||
$write = [];
|
|
||||||
|
|
||||||
for($i = 0; $i < 1024; ++$i){
|
|
||||||
$write[] = (($this->locationTable[$i]->getFirstSector() << 8) | $this->locationTable[$i]->getSectorCount());
|
|
||||||
}
|
|
||||||
for($i = 0; $i < 1024; ++$i){
|
|
||||||
$write[] = $this->locationTable[$i]->getTimestamp();
|
|
||||||
}
|
|
||||||
fseek($this->filePointer, 0);
|
|
||||||
fwrite($this->filePointer, pack("N*", ...$write), 4096 * 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function writeLocationIndex(int $index) : void{
|
protected function writeLocationIndex(int $index) : void{
|
||||||
fseek($this->filePointer, $index << 2);
|
fseek($this->filePointer, $index << 2);
|
||||||
fwrite($this->filePointer, Binary::writeInt(($this->locationTable[$index]->getFirstSector() << 8) | $this->locationTable[$index]->getSectorCount()), 4);
|
fwrite($this->filePointer, Binary::writeInt(($this->locationTable[$index]->getFirstSector() << 8) | $this->locationTable[$index]->getSectorCount()), 4);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user