Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Slight optimization of getBlockname() #136

Merged
merged 1 commit into from

2 participants

@linusnielsen

I made it use a hash instead of a linear search with exploding the items for each row.

@GoalieGuy6
Collaborator

Thanks!

@GoalieGuy6 GoalieGuy6 merged commit c6eb5cf into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 20, 2012
  1. @linusnielsen

    Optimize getBlockName()

    linusnielsen authored
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 10 deletions.
  1. +11 −10 HawkEye Interface/interface.php
View
21 HawkEye Interface/interface.php
@@ -136,6 +136,10 @@
return error(mysql_error());
$items = explode("\n", file_get_contents("items.txt"));
+ foreach($items as $i) {
+ $item = explode(",", $i);
+ $itemhash[intval($item[0])] = $item[1];
+ }
$results = array();
//Get results from MySQL
@@ -214,15 +218,12 @@
*/
function getBlockName($string) {
global $items;
- $parts = explode(":", $string);
- foreach ($items as $i) {
- $item = explode(",", $i);
- if ($item[0] == $parts[0]) {
- if (count($parts) == 2)
- return $item[1] . ":" . $parts[1];
- else return $item[1];
- }
- }
+ global $itemhash;
+ $i = $itemhash[$parts[0]];
+ if($i) {
+ if (count($parts) == 2)
+ return $i . ":" . $parts[1];
+ else return $i;
return $string;
}
@@ -241,4 +242,4 @@ function error($message) {
echo json_encode($output);
}
-?>
+?>
Something went wrong with that request. Please try again.