-
Notifications
You must be signed in to change notification settings - Fork 3.6k
refactor: cleanup code twice calling #4499
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -608,7 +608,7 @@ public function addSheet(Worksheet $worksheet, ?int $sheetIndex = null, bool $re | |
*/ | ||
public function removeSheetByIndex(int $sheetIndex): void | ||
{ | ||
$numSheets = count($this->workSheetCollection); | ||
$numSheets = $this->getSheetCount(); | ||
if ($sheetIndex > $numSheets - 1) { | ||
throw new Exception( | ||
"You tried to remove a sheet by the out of bounds index: {$sheetIndex}. The actual number of sheets is {$numSheets}." | ||
|
@@ -660,9 +660,10 @@ public function getAllSheets(): array | |
*/ | ||
public function getSheetByName(string $worksheetName): ?Worksheet | ||
{ | ||
$worksheetCount = count($this->workSheetCollection); | ||
for ($i = 0; $i < $worksheetCount; ++$i) { | ||
if (strcasecmp($this->workSheetCollection[$i]->getTitle(), trim($worksheetName, "'")) === 0) { | ||
$trimWorksheetName = trim($worksheetName, "'"); | ||
|
||
for ($i = 0; $i < $this->getSheetCount(); ++$i) { | ||
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. This absolutely adds overhead by moving a function call from outside the loop to inside. It will definitely not be approved. |
||
if (strcasecmp($this->workSheetCollection[$i]->getTitle(), $trimWorksheetName) === 0) { | ||
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. This one, however, does improve things a bit by moving a function call from inside the loop to outside. I would certainly be okay with including this part. |
||
return $this->workSheetCollection[$i]; | ||
} | ||
} | ||
|
@@ -790,8 +791,8 @@ public function setActiveSheetIndexByName(string $worksheetName): Worksheet | |
public function getSheetNames(): array | ||
{ | ||
$returnValue = []; | ||
$worksheetCount = $this->getSheetCount(); | ||
for ($i = 0; $i < $worksheetCount; ++$i) { | ||
|
||
for ($i = 0; $i < $this->getSheetCount(); ++$i) { | ||
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. Once again, you are moving a function call from outside the loop to inside. This part of the change will not be approved. |
||
$returnValue[] = $this->getSheet($i)->getTitle(); | ||
} | ||
|
||
|
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.
This change seems to add a small amount of overhead through an additional function call. What compensatory advantage do you see that would make this worthwhile?