Make WordPress Core

Ticket #30430: wp-deep-copy-2.diff

File wp-deep-copy-2.diff, 1004 bytes (added by jipmoors, 10 years ago)

optimization: removing duplicate functionality

  • src/wp-includes/cache.php

     
    244244}
    245245
    246246/**
     247 * Performs a deep copy of an item to ensure that arrays of objects
     248 * are properly duplicated
     249 *
     250 * @param mixed $data The data to be duplicated
     251 * @return mixed copy of the data
     252 */
     253function wp_deep_copy( $data ) {
     254        if ( is_object( $data ) ) {
     255                return clone $data;
     256        } elseif ( is_array( $data ) ) {
     257                $new = array();
     258
     259                foreach ( $data as $key => $value ) {
     260                        $new[ $key ] = wp_deep_copy( $value );
     261                }
     262
     263                return $new;
     264        }
     265
     266        return $data;
     267}
     268
     269/**
    247270 * WordPress Object Cache
    248271 *
    249272 * The WordPress Object Cache is used to save on trips to the database. The
     
    619642
    620643                if ( is_object( $data ) )
    621644                        $data = clone $data;
     645                elseif ( is_array( $data ) )
     646                        $data = wp_deep_copy( $data );
    622647
    623648                $this->cache[$group][$key] = $data;
    624649                return true;