Skip to content

Commit

Permalink
Optimize getBlockName()
Browse files Browse the repository at this point in the history
  • Loading branch information
linusnielsen committed Mar 20, 2012
1 parent 602bdd1 commit 8b77453
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions HawkEye Interface/interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand All @@ -241,4 +242,4 @@ function error($message) {
echo json_encode($output);
}

?>
?>

0 comments on commit 8b77453

Please sign in to comment.