summaryrefslogtreecommitdiffstats
path: root/system/libraries
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-11-12 16:21:01 +0100
committerAndrey Andreev <narf@bofh.bg>2012-11-12 16:21:01 +0100
commit7a7ad782b2f125622509a77c5a6f94ad4ae0f93c (patch)
tree8b849b80e51492877c60a7b976d33a0ddba68d46 /system/libraries
parenta9ab46d7a031bda304eb9b6658ffaf693b8d9bcb (diff)
Some micro-optimizations
Diffstat (limited to 'system/libraries')
-rw-r--r--system/libraries/Email.php4
-rw-r--r--system/libraries/Form_validation.php20
-rw-r--r--system/libraries/Image_lib.php12
-rw-r--r--system/libraries/Trackback.php2
4 files changed, 14 insertions, 24 deletions
diff --git a/system/libraries/Email.php b/system/libraries/Email.php
index d23be1af1..92ccde60c 100644
--- a/system/libraries/Email.php
+++ b/system/libraries/Email.php
@@ -1935,7 +1935,7 @@ class CI_Email {
$this->_debug_msg[] = '<pre>'.$cmd.': '.$reply.'</pre>';
- if ( (int) substr($reply, 0, 3) !== $resp)
+ if ((int) substr($reply, 0, 3) !== $resp)
{
$this->_set_error_message('lang:email_smtp_error', $reply);
return FALSE;
@@ -2093,7 +2093,7 @@ class CI_Email {
$CI =& get_instance();
$CI->lang->load('email');
- if (substr($msg, 0, 5) !== 'lang:' OR FALSE === ($line = $CI->lang->line(substr($msg, 5))))
+ if (sscanf($msg, 'lang:%s', $line) !== 1 OR FALSE === ($line = $CI->lang->line($line)))
{
$this->_debug_msg[] = str_replace('%s', $val, $msg).'<br />';
}
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index e50eee4f2..b0ba8bbcb 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -199,12 +199,10 @@ class CI_Form_validation {
// Is the field name an array? If it is an array, we break it apart
// into its components so that we can fetch the corresponding POST data later
+ $indexes = array();
if (preg_match_all('/\[(.*?)\]/', $field, $matches))
{
- // Note: Due to a bug in current() that affects some versions
- // of PHP we can not pass function call directly into it
- $x = explode('[', $field);
- $indexes[] = current($x);
+ sscanf($field, '%[^[][', $indexes[0]);
for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
{
@@ -218,7 +216,6 @@ class CI_Form_validation {
}
else
{
- $indexes = array();
$is_array = FALSE;
}
@@ -673,11 +670,7 @@ class CI_Form_validation {
// Strip the parameter (if exists) from the rule
// Rules can contain a parameter: max_length[5]
$param = FALSE;
- if (preg_match('/(.*?)\[(.*)\]/', $rule, $match))
- {
- $rule = $match[1];
- $param = $match[2];
- }
+ sscanf($rule, '%[^[][%[^]]', $rule, $param);
// Call the function that corresponds to the rule
if ($callback === TRUE)
@@ -796,11 +789,8 @@ class CI_Form_validation {
{
// Do we need to translate the field name?
// We look for the prefix lang: to determine this
- if (strpos($fieldname, 'lang:') === 0)
+ if (sscanf($fieldname, 'lang:%s', $line) === 1)
{
- // Grab the variable
- $line = substr($fieldname, 5);
-
// Were we able to translate the field name? If not we use $line
if (FALSE === ($fieldname = $this->CI->lang->line($line)))
{
@@ -1002,7 +992,7 @@ class CI_Form_validation {
*/
public function is_unique($str, $field)
{
- list($table, $field) = explode('.', $field);
+ sscanf($field, '%[^.].%[^.]', $table, $field);
if (isset($this->CI->db))
{
$query = $this->CI->db->limit(1)->get_where($table, array($field => $str));
diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php
index 9379e3ec8..7f937f99b 100644
--- a/system/libraries/Image_lib.php
+++ b/system/libraries/Image_lib.php
@@ -605,7 +605,7 @@ class CI_Image_lib {
// Set the quality
$this->quality = trim(str_replace('%', '', $this->quality));
- if ($this->quality === '' OR $this->quality === 0 OR ! preg_match('/^[0-9]+$/', $this->quality))
+ if ($this->quality === '' OR $this->quality === 0 OR ! ctype_digit($this->quality))
{
$this->quality = 90;
}
@@ -1277,8 +1277,8 @@ class CI_Image_lib {
if ($this->wm_use_drop_shadow === FALSE)
$this->wm_shadow_distance = 0;
- $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1));
- $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1));
+ $this->wm_vrt_alignment = strtoupper($this->wm_vrt_alignment[0]);
+ $this->wm_hor_alignment = strtoupper($this->wm_hor_alignment[0]);
// Set verticle alignment
if ($this->wm_vrt_alignment === 'M')
@@ -1518,13 +1518,13 @@ class CI_Image_lib {
public function image_reproportion()
{
if (($this->width === 0 && $this->height === 0) OR $this->orig_width === 0 OR $this->orig_height === 0
- OR ( ! preg_match('/^[0-9]+$/', $this->width) && ! preg_match('/^[0-9]+$/', $this->height))
- OR ! preg_match('/^[0-9]+$/', $this->orig_width) OR ! preg_match('/^[0-9]+$/', $this->orig_height))
+ OR ( ! ctype_digit((string) $this->width) && ! ctype_digit((string) $this->height))
+ OR ! ctype_digit((string) $this->orig_width) OR ! ctype_digit((string) $this->orig_height))
{
return;
}
- // Sanitize so we don't call preg_match() anymore
+ // Sanitize
$this->width = (int) $this->width;
$this->height = (int) $this->height;
diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php
index c923a6220..d30350340 100644
--- a/system/libraries/Trackback.php
+++ b/system/libraries/Trackback.php
@@ -394,7 +394,7 @@ class CI_Trackback {
}
}
- return preg_match('/^[0-9]+$/', $tb_id) ? $tb_id : FALSE;
+ return ctype_digit((string) $tb_id) ? $tb_id : FALSE;
}
// --------------------------------------------------------------------