-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improved performance of column width calculation for spreadsheets wit… #1628
Changes from all commits
238b55e
490cf15
2208a26
9e5b37d
817bde8
8da53f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -496,16 +496,27 @@ public function isInMergeRange() | |
public function isMergeRangeValueCell() | ||
{ | ||
if ($mergeRange = $this->getMergeRange()) { | ||
$mergeRange = Coordinate::splitRange($mergeRange); | ||
[$startCell] = $mergeRange[0]; | ||
if ($this->getCoordinate() === $startCell) { | ||
return true; | ||
} | ||
return $this->isMergeRangeValueCell2($mergeRange); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Is this cell the master (top left cell) in a merge range (that holds the actual data value). | ||
* | ||
* @param string $mergeRange merge range from getMergeRange() | ||
* | ||
* @return bool | ||
*/ | ||
public function isMergeRangeValueCell2($mergeRange) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idea for perhaps better name: |
||
{ | ||
$splittedRanges = Coordinate::splitRange($mergeRange); | ||
[$startCell] = $splittedRanges[0]; | ||
|
||
return $this->getCoordinate() === $startCell; | ||
} | ||
|
||
/** | ||
* If this cell is in a merge range, then return the range. | ||
* | ||
|
@@ -555,13 +566,15 @@ public function isInRange($pRange) | |
{ | ||
[$rangeStart, $rangeEnd] = Coordinate::rangeBoundaries($pRange); | ||
|
||
// Translate properties | ||
$myColumn = Coordinate::columnIndexFromString($this->getColumn()); | ||
// Verify if cell is in range | ||
$myRow = $this->getRow(); | ||
if ($rangeStart[1] <= $myRow && $rangeEnd[1] >= $myRow) { | ||
$myColumn = Coordinate::columnIndexFromString($this->getColumn()); | ||
|
||
// Verify if cell is in range | ||
return ($rangeStart[0] <= $myColumn) && ($rangeEnd[0] >= $myColumn) && | ||
($rangeStart[1] <= $myRow) && ($rangeEnd[1] >= $myRow); | ||
return ($rangeStart[0] <= $myColumn) && ($rangeEnd[0] >= $myColumn); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,13 @@ | |
*/ | ||
abstract class Coordinate | ||
{ | ||
/** | ||
* Cache for rangeBoundaries. | ||
* | ||
* @var array | ||
*/ | ||
private static $_rangeBoundariesCache = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using underscore in variable name is almost never used in this project. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. We're trying to move away from underscore usage. So new usage should not be added again. |
||
|
||
/** | ||
* Default range variable constant. | ||
* | ||
|
@@ -167,6 +174,10 @@ public static function buildRange(array $pRange) | |
*/ | ||
public static function rangeBoundaries($pRange) | ||
{ | ||
if (isset(self::$_rangeBoundariesCache[$pRange])) { | ||
return self::$_rangeBoundariesCache[$pRange]; | ||
} | ||
|
||
// Ensure $pRange is a valid range | ||
if (empty($pRange)) { | ||
$pRange = self::DEFAULT_RANGE; | ||
|
@@ -184,12 +195,14 @@ public static function rangeBoundaries($pRange) | |
|
||
// Calculate range outer borders | ||
$rangeStart = self::coordinateFromString($rangeA); | ||
$rangeEnd = self::coordinateFromString($rangeB); | ||
$rangeEnd = $rangeA === $rangeB ? $rangeStart : self::coordinateFromString($rangeB); | ||
|
||
// Translate column into index | ||
$rangeStart[0] = self::columnIndexFromString($rangeStart[0]); | ||
$rangeEnd[0] = self::columnIndexFromString($rangeEnd[0]); | ||
|
||
self::$_rangeBoundariesCache[$pRange] = [$rangeStart, $rangeEnd]; | ||
|
||
return [$rangeStart, $rangeEnd]; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All new methods must declare their typing