@@ -431,23 +431,23 @@ class String
431431 zend_string_free (value);
432432 }
433433 }
434- size_t length ()
434+ inline size_t length ()
435435 {
436436 return value->len ;
437437 }
438- char * c_str ()
438+ inline char * c_str ()
439439 {
440440 return value->val ;
441441 }
442- void extend (size_t new_size)
442+ inline void extend (size_t new_size)
443443 {
444444 value = zend_string_extend (value, new_size, 0 );
445445 }
446- bool equals (const char *str)
446+ inline bool equals (const char *str)
447447 {
448448 return memcmp (str, value->val , value->len ) == 0 ;
449449 }
450- bool equals (string &str)
450+ inline bool equals (string &str)
451451 {
452452 if (str.length () != value->len )
453453 {
@@ -467,72 +467,12 @@ class String
467467 }
468468 return memcmp (str.c_str (), value->val , value->len ) == 0 ;
469469 }
470- void tolower ()
470+ inline void tolower ()
471471 {
472472 zend_str_tolower (value->val , value->len );
473473 }
474- String substr (long _offset, long _length = -1 )
475- {
476- if ((_length < 0 && (size_t ) (-_length) > this ->length ()))
477- {
478- return " " ;
479- }
480- else if (_length > (zend_long) this ->length ())
481- {
482- _length = this ->length ();
483- }
484-
485- if (_offset > (zend_long) this ->length ())
486- {
487- return " " ;
488- }
489- else if (_offset < 0 && -_offset > this ->length ())
490- {
491- _offset = 0 ;
492- }
493-
494- if (_length < 0 && (_length + (zend_long) this ->length () - _offset) < 0 )
495- {
496- return " " ;
497- }
498-
499- /* if "from" position is negative, count start position from the end
500- * of the string
501- */
502- if (_offset < 0 )
503- {
504- _offset = (zend_long) this ->length () + _offset;
505- if (_offset < 0 )
506- {
507- _offset = 0 ;
508- }
509- }
510-
511- /* if "length" position is negative, set it to the length
512- * needed to stop that many chars from the end of the string
513- */
514- if (_length < 0 )
515- {
516- _length = ((zend_long) this ->length () - _offset) + _length;
517- if (_length < 0 )
518- {
519- _length = 0 ;
520- }
521- }
522-
523- if (_offset > (zend_long) this ->length ())
524- {
525- return " " ;
526- }
527-
528- if ((_offset + _length) > (zend_long) this ->length ())
529- {
530- _length = this ->length () - _offset;
531- }
532-
533- return String (value->val + _offset, _length);
534- }
535- zend_string* ptr ()
474+ String substr (long _offset, long _length = -1 );
475+ inline zend_string* ptr ()
536476 {
537477 return value;
538478 }
@@ -829,102 +769,7 @@ class Array: public Variant
829769 {
830770 return zend_hash_sort (Z_ARRVAL_P (ptr ()), array_data_compare, 1 ) == SUCCESS;
831771 }
832- Array slice (long offset, long length = -1 , bool preserve_keys = false )
833- {
834- size_t num_in = count ();
835-
836- if (offset > num_in)
837- {
838- return Array ();
839- }
840- else if (offset < 0 && (offset = (num_in + offset)) < 0 )
841- {
842- offset = 0 ;
843- }
844-
845- if (length < 0 )
846- {
847- length = num_in - offset + length;
848- }
849- else if (((zend_ulong) offset + (zend_ulong) length) > (unsigned ) num_in)
850- {
851- length = num_in - offset;
852- }
853-
854- if (length <= 0 )
855- {
856- return Array ();
857- }
858-
859- zend_string *string_key;
860- zend_ulong num_key;
861- zval *entry;
862-
863- zval return_value;
864- array_init_size (&return_value, (uint32_t ) length);
865-
866- /* Start at the beginning and go until we hit offset */
867- int pos = 0 ;
868- if (!preserve_keys && (Z_ARRVAL_P (this ->ptr ())->u .flags & HASH_FLAG_PACKED))
869- {
870- zend_hash_real_init (Z_ARRVAL_P (&return_value), 1 );
871- ZEND_HASH_FILL_PACKED (Z_ARRVAL_P (&return_value))
872- {
873- ZEND_HASH_FOREACH_VAL (Z_ARRVAL_P (this ->ptr ()), entry)
874- {
875- pos++;
876- if (pos <= offset)
877- {
878- continue ;
879- }
880- if (pos > offset + length)
881- {
882- break ;
883- }
884- ZEND_HASH_FILL_ADD (entry);
885- zval_add_ref (entry);
886- }
887- ZEND_HASH_FOREACH_END ();
888- }
889- ZEND_HASH_FILL_END ();
890- }
891- else
892- {
893- ZEND_HASH_FOREACH_KEY_VAL (Z_ARRVAL_P (this ->ptr ()), num_key, string_key, entry)
894- {
895- pos++;
896- if (pos <= offset)
897- {
898- continue ;
899- }
900- if (pos > offset + length)
901- {
902- break ;
903- }
904-
905- if (string_key)
906- {
907- entry = zend_hash_add_new (Z_ARRVAL_P (&return_value), string_key, entry);
908- }
909- else
910- {
911- if (preserve_keys)
912- {
913- entry = zend_hash_index_add_new (Z_ARRVAL_P (&return_value), num_key, entry);
914- }
915- else
916- {
917- entry = zend_hash_next_index_insert_new (Z_ARRVAL_P (&return_value), entry);
918- }
919- }
920- zval_add_ref (entry);
921- }
922- ZEND_HASH_FOREACH_END ();
923- }
924- Array retval (&return_value);
925- retval.addRef ();
926- return retval;
927- }
772+ Array slice (long offset, long length = -1 , bool preserve_keys = false );
928773};
929774
930775extern int arg_list_size;
@@ -1817,56 +1662,7 @@ class Extension
18171662 return true ;
18181663 }
18191664
1820- bool registerFunction (const char *name, function_t func, ArgInfo *info = nullptr )
1821- {
1822- this ->checkStartupStatus (BEFORE_START, __func__);
1823- if (module .functions == NULL )
1824- {
1825- module .functions = (const zend_function_entry*) calloc (16 , sizeof (zend_function_entry));
1826- if (module .functions == NULL )
1827- {
1828- return false ;
1829- }
1830- function_array_size = 16 ;
1831- }
1832- else if (function_count + 1 == function_array_size)
1833- {
1834- function_array_size *= 2 ;
1835- void * new_array = realloc ((void *) module .functions , function_array_size * sizeof (zend_function_entry));
1836- if (new_array == NULL )
1837- {
1838- return false ;
1839- }
1840- module .functions = (const zend_function_entry*) new_array;
1841- }
1842-
1843- zend_function_entry *function_array = (zend_function_entry *) module .functions ;
1844- function_array[function_count].fname = name;
1845-
1846- function_array[function_count].handler = _exec_function;
1847- function_array[function_count].arg_info = NULL ;
1848- function_array[function_count].num_args = 0 ;
1849- function_array[function_count].flags = 0 ;
1850- if (info)
1851- {
1852- function_array[function_count].arg_info = info->get ();
1853- function_array[function_count].num_args = info->count ();
1854- }
1855- else
1856- {
1857- function_array[function_count].arg_info = NULL ;
1858- function_array[function_count].num_args = 0 ;
1859- }
1860-
1861- function_array[function_count + 1 ].fname = NULL ;
1862- function_array[function_count + 1 ].handler = NULL ;
1863- function_array[function_count + 1 ].flags = 0 ;
1864-
1865- function_map[name] = func;
1866-
1867- function_count ++;
1868- return true ;
1869- }
1665+ bool registerFunction (const char *name, function_t func, ArgInfo *info = nullptr );
18701666
18711667 bool registerResource (const char *name, resource_dtor dtor)
18721668 {
@@ -1978,43 +1774,7 @@ class Extension
19781774 return zend_register_constant (&c);
19791775 }
19801776
1981- bool require (const char *name, const char *version = nullptr )
1982- {
1983- this ->checkStartupStatus (BEFORE_START, __func__);
1984- if (module .deps == NULL )
1985- {
1986- module .deps = (const zend_module_dep*) calloc (16 , sizeof (zend_module_dep));
1987- if (module .deps == NULL )
1988- {
1989- return false ;
1990- }
1991- deps_array_size = 16 ;
1992- }
1993- else if (deps_count + 1 == deps_array_size)
1994- {
1995- deps_array_size *= 2 ;
1996- void * new_array = realloc ((void *) module .deps , deps_array_size * sizeof (zend_module_dep));
1997- if (new_array == NULL )
1998- {
1999- return false ;
2000- }
2001- module .deps = (const zend_module_dep*) new_array;
2002- }
2003-
2004- zend_module_dep *deps_array = (zend_module_dep *) module .deps ;
2005- deps_array[deps_count].name = name;
2006- deps_array[deps_count].rel = NULL ;
2007- deps_array[deps_count].version = version;
2008- deps_array[deps_count].type = MODULE_DEP_REQUIRED;
2009-
2010- deps_array[deps_count + 1 ].name = NULL ;
2011- deps_array[deps_count + 1 ].rel = NULL ;
2012- deps_array[deps_count + 1 ].version = NULL ;
2013- deps_array[deps_count + 1 ].type = 0 ;
2014-
2015- deps_count++;
2016- return true ;
2017- }
1777+ bool require (const char *name, const char *version = nullptr );
20181778
20191779 void info (vector<string> header, vector<vector<string> > body)
20201780 {
0 commit comments