mirror of
https://github.com/MariaDB/server.git
synced 2025-01-31 19:11:46 +01:00
d82eaad5fe
Get rid of O(n^2) scan in dyn array (mtr->memo) operations, accessing the dyn array blocks directly. dyn_array_get_last_block(), dyn_array_get_next_block(), dyn_array_get_prev_block(): Define as a constness-preserving macro. Add const qualifiers to many dyn_array functions. mtr_memo_slot_release_func(): Renamed from mtr_memo_slot_release(): Make mtr_t* a debug-only parameter. Assume that slot->object != NULL. mtr_memo_pop_all(): Access the dyn_array blocks directly, replacing O(n^2) operation with O(n). mtr_memo_release(): Access the dyn_array blocks directly, replacing O(n^2) operation with O(n). This caused the performance problem. rb#1540 approved by Jimmy Yang
65 lines
1.8 KiB
C
65 lines
1.8 KiB
C
/*****************************************************************************
|
|
|
|
Copyright (c) 1996, 2013, Oracle and/or its affiliates. All Rights Reserved.
|
|
|
|
This program is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free Software
|
|
Foundation; version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
this program; if not, write to the Free Software Foundation, Inc.,
|
|
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
|
|
|
|
*****************************************************************************/
|
|
|
|
/**************************************************//**
|
|
@file dyn/dyn0dyn.c
|
|
The dynamically allocated array
|
|
|
|
Created 2/5/1996 Heikki Tuuri
|
|
*******************************************************/
|
|
|
|
#include "dyn0dyn.h"
|
|
#ifdef UNIV_NONINL
|
|
#include "dyn0dyn.ic"
|
|
#endif
|
|
|
|
/************************************************************//**
|
|
Adds a new block to a dyn array.
|
|
@return created block */
|
|
UNIV_INTERN
|
|
dyn_block_t*
|
|
dyn_array_add_block(
|
|
/*================*/
|
|
dyn_array_t* arr) /*!< in/out: dyn array */
|
|
{
|
|
mem_heap_t* heap;
|
|
dyn_block_t* block;
|
|
|
|
ut_ad(arr);
|
|
ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N);
|
|
|
|
if (arr->heap == NULL) {
|
|
UT_LIST_INIT(arr->base);
|
|
UT_LIST_ADD_FIRST(list, arr->base, arr);
|
|
|
|
arr->heap = mem_heap_create(sizeof(dyn_block_t));
|
|
}
|
|
|
|
block = dyn_array_get_last_block(arr);
|
|
block->used = block->used | DYN_BLOCK_FULL_FLAG;
|
|
|
|
heap = arr->heap;
|
|
|
|
block = mem_heap_alloc(heap, sizeof(dyn_block_t));
|
|
|
|
block->used = 0;
|
|
|
|
UT_LIST_ADD_LAST(list, arr->base, block);
|
|
|
|
return(block);
|
|
}
|