PostgreSQL Source Code  git master
list.c File Reference
#include "postgres.h"
#include "nodes/pg_list.h"
#include "utils/memdebug.h"
#include "utils/memutils.h"
Include dependency graph for list.c:

Go to the source code of this file.

Macros

#define LIST_HEADER_OVERHEAD   ((int) ((offsetof(List, initial_elements) - 1) / sizeof(ListCell) + 1))
 
#define IsPointerList(l)   ((l) == NIL || IsA((l), List))
 
#define IsIntegerList(l)   ((l) == NIL || IsA((l), IntList))
 
#define IsOidList(l)   ((l) == NIL || IsA((l), OidList))
 
#define check_list_invariants(l)   ((void) 0)
 

Functions

static Listnew_list (NodeTag type, int min_size)
 
static void enlarge_list (List *list, int min_size)
 
Listlist_make1_impl (NodeTag t, ListCell datum1)
 
Listlist_make2_impl (NodeTag t, ListCell datum1, ListCell datum2)
 
Listlist_make3_impl (NodeTag t, ListCell datum1, ListCell datum2, ListCell datum3)
 
Listlist_make4_impl (NodeTag t, ListCell datum1, ListCell datum2, ListCell datum3, ListCell datum4)
 
static void new_head_cell (List *list)
 
static void new_tail_cell (List *list)
 
Listlappend (List *list, void *datum)
 
Listlappend_int (List *list, int datum)
 
Listlappend_oid (List *list, Oid datum)
 
static ListCellinsert_new_cell (List *list, int pos)
 
Listlist_insert_nth (List *list, int pos, void *datum)
 
Listlist_insert_nth_int (List *list, int pos, int datum)
 
Listlist_insert_nth_oid (List *list, int pos, Oid datum)
 
Listlcons (void *datum, List *list)
 
Listlcons_int (int datum, List *list)
 
Listlcons_oid (Oid datum, List *list)
 
Listlist_concat (List *list1, const List *list2)
 
Listlist_concat_copy (const List *list1, const List *list2)
 
Listlist_truncate (List *list, int new_size)
 
bool list_member (const List *list, const void *datum)
 
bool list_member_ptr (const List *list, const void *datum)
 
bool list_member_int (const List *list, int datum)
 
bool list_member_oid (const List *list, Oid datum)
 
Listlist_delete_nth_cell (List *list, int n)
 
Listlist_delete_cell (List *list, ListCell *cell)
 
Listlist_delete (List *list, void *datum)
 
Listlist_delete_ptr (List *list, void *datum)
 
Listlist_delete_int (List *list, int datum)
 
Listlist_delete_oid (List *list, Oid datum)
 
Listlist_delete_first (List *list)
 
Listlist_delete_last (List *list)
 
Listlist_union (const List *list1, const List *list2)
 
Listlist_union_ptr (const List *list1, const List *list2)
 
Listlist_union_int (const List *list1, const List *list2)
 
Listlist_union_oid (const List *list1, const List *list2)
 
Listlist_intersection (const List *list1, const List *list2)
 
Listlist_intersection_int (const List *list1, const List *list2)
 
Listlist_difference (const List *list1, const List *list2)
 
Listlist_difference_ptr (const List *list1, const List *list2)
 
Listlist_difference_int (const List *list1, const List *list2)
 
Listlist_difference_oid (const List *list1, const List *list2)
 
Listlist_append_unique (List *list, void *datum)
 
Listlist_append_unique_ptr (List *list, void *datum)
 
Listlist_append_unique_int (List *list, int datum)
 
Listlist_append_unique_oid (List *list, Oid datum)
 
Listlist_concat_unique (List *list1, const List *list2)
 
Listlist_concat_unique_ptr (List *list1, const List *list2)
 
Listlist_concat_unique_int (List *list1, const List *list2)
 
Listlist_concat_unique_oid (List *list1, const List *list2)
 
void list_deduplicate_oid (List *list)
 
static void list_free_private (List *list, bool deep)
 
void list_free (List *list)
 
void list_free_deep (List *list)
 
Listlist_copy (const List *oldlist)
 
Listlist_copy_tail (const List *oldlist, int nskip)
 
Listlist_copy_deep (const List *oldlist)
 
void list_sort (List *list, list_sort_comparator cmp)
 
int list_oid_cmp (const ListCell *p1, const ListCell *p2)
 

Macro Definition Documentation

◆ check_list_invariants

◆ IsIntegerList

#define IsIntegerList (   l)    ((l) == NIL || IsA((l), IntList))

◆ IsOidList

#define IsOidList (   l)    ((l) == NIL || IsA((l), OidList))

◆ IsPointerList

◆ LIST_HEADER_OVERHEAD

#define LIST_HEADER_OVERHEAD   ((int) ((offsetof(List, initial_elements) - 1) / sizeof(ListCell) + 1))

Definition at line 46 of file list.c.

Referenced by new_list().

Function Documentation

◆ enlarge_list()

static void enlarge_list ( List list,
int  min_size 
)
static

Definition at line 153 of file list.c.

References Assert, List::elements, GetMemoryChunkContext(), List::initial_elements, List::length, List::max_length, MemoryContextAlloc(), pfree(), repalloc(), and VALGRIND_MAKE_MEM_NOACCESS.

Referenced by insert_new_cell(), list_concat(), new_head_cell(), and new_tail_cell().

154 {
155  int new_max_len;
156 
157  Assert(min_size > list->max_length); /* else we shouldn't be here */
158 
159 #ifndef DEBUG_LIST_MEMORY_USAGE
160 
161  /*
162  * As above, we prefer power-of-two total allocations; but here we need
163  * not account for list header overhead. The existing max length might
164  * not be a power of 2, so don't rely on that.
165  */
166  new_max_len = 16; /* semi-arbitrary small power of 2 */
167  while (new_max_len < min_size)
168  new_max_len *= 2;
169 #else
170  /* As above, don't allocate anything extra */
171  new_max_len = min_size;
172 #endif
173 
174  if (list->elements == list->initial_elements)
175  {
176  /*
177  * Replace original in-line allocation with a separate palloc block.
178  * Ensure it is in the same memory context as the List header. (The
179  * previous List implementation did not offer any guarantees about
180  * keeping all list cells in the same context, but it seems reasonable
181  * to create such a guarantee now.)
182  */
183  list->elements = (ListCell *)
185  new_max_len * sizeof(ListCell));
186  memcpy(list->elements, list->initial_elements,
187  list->length * sizeof(ListCell));
188 
189  /*
190  * We must not move the list header, so it's unsafe to try to reclaim
191  * the initial_elements[] space via repalloc. In debugging builds,
192  * however, we can clear that space and/or mark it inaccessible.
193  * (wipe_mem includes VALGRIND_MAKE_MEM_NOACCESS.)
194  */
195 #ifdef CLOBBER_FREED_MEMORY
196  wipe_mem(list->initial_elements,
197  list->max_length * sizeof(ListCell));
198 #else
200  list->max_length * sizeof(ListCell));
201 #endif
202  }
203  else
204  {
205 #ifndef DEBUG_LIST_MEMORY_USAGE
206  /* Normally, let repalloc deal with enlargement */
207  list->elements = (ListCell *) repalloc(list->elements,
208  new_max_len * sizeof(ListCell));
209 #else
210  /*
211  * repalloc() might enlarge the space in-place, which we don't want
212  * for debugging purposes, so forcibly move the data somewhere else.
213  */
214  ListCell *newelements;
215 
216  newelements = (ListCell *)
218  new_max_len * sizeof(ListCell));
219  memcpy(newelements, list->elements,
220  list->length * sizeof(ListCell));
221  pfree(list->elements);
222  list->elements = newelements;
223 #endif
224  }
225 
226  list->max_length = new_max_len;
227 }
#define VALGRIND_MAKE_MEM_NOACCESS(addr, size)
Definition: memdebug.h:27
void pfree(void *pointer)
Definition: mcxt.c:1056
union ListCell ListCell
int max_length
Definition: pg_list.h:54
ListCell * elements
Definition: pg_list.h:55
#define Assert(condition)
Definition: c.h:739
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1069
int length
Definition: pg_list.h:53
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:796
ListCell initial_elements[FLEXIBLE_ARRAY_MEMBER]
Definition: pg_list.h:57
static MemoryContext GetMemoryChunkContext(void *pointer)
Definition: memutils.h:113

◆ insert_new_cell()

static ListCell* insert_new_cell ( List list,
int  pos 
)
static

Definition at line 380 of file list.c.

References Assert, List::elements, enlarge_list(), List::length, List::max_length, and memmove.

Referenced by list_insert_nth(), list_insert_nth_int(), and list_insert_nth_oid().

381 {
382  Assert(pos >= 0 && pos <= list->length);
383 
384  /* Enlarge array if necessary */
385  if (list->length >= list->max_length)
386  enlarge_list(list, list->length + 1);
387  /* Now shove the existing data over */
388  if (pos < list->length)
389  memmove(&list->elements[pos + 1], &list->elements[pos],
390  (list->length - pos) * sizeof(ListCell));
391  list->length++;
392 
393  return &list->elements[pos];
394 }
static void enlarge_list(List *list, int min_size)
Definition: list.c:153
#define memmove(d, s, c)
Definition: c.h:1267
int max_length
Definition: pg_list.h:54
ListCell * elements
Definition: pg_list.h:55
#define Assert(condition)
Definition: c.h:739
int length
Definition: pg_list.h:53

◆ lappend()

List* lappend ( List list,
void *  datum 
)

Definition at line 322 of file list.c.

References Assert, check_list_invariants, IsPointerList, lfirst, sort-test::list, list_tail(), new_list(), new_tail_cell(), NIL, and T_List.

Referenced by _SPI_make_plan_non_temp(), _SPI_prepare_oneshot_plan(), _SPI_prepare_plan(), _SPI_save_plan(), accumulate_append_subpath(), AcquireRewriteLocks(), add_column_to_pathtarget(), add_dummy_return(), add_eq_member(), add_join_clause_to_rels(), add_join_rel(), add_paths_to_append_rel(), add_placeholders_to_base_rels(), add_placeholders_to_joinrel(), add_rte_to_flat_rtable(), add_security_quals(), add_to_flat_tlist(), add_unique_group_var(), add_vars_to_targetlist(), add_with_check_options(), addArc(), AddEventToPendingNotifies(), addFamilyMember(), addFkRecurseReferencing(), addKey(), addKeyToQueue(), addRangeTableEntry(), addRangeTableEntryForCTE(), addRangeTableEntryForENR(), addRangeTableEntryForFunction(), addRangeTableEntryForJoin(), addRangeTableEntryForRelation(), addRangeTableEntryForSubquery(), addRangeTableEntryForTableFunc(), addRangeTableEntryForValues(), AddRelationNewConstraints(), addRTEtoQuery(), addTargetToGroupList(), addTargetToSortList(), adjust_inherited_tlist(), adjust_partition_tlist(), AlterPublicationTables(), AlterTableMoveAll(), AlterTSDictionary(), analyzeCTETargetList(), apply_child_basequals(), apply_handle_truncate(), apply_scanjoin_target_to_paths(), applyLockingClause(), ApplyRetrieveRule(), assign_param_for_placeholdervar(), assign_param_for_var(), ATAddCheckConstraint(), ATExecAddColumn(), ATGetQueueEntry(), ATPostAlterTypeParse(), ATPrepAlterColumnType(), ATPrepCmd(), btcostestimate(), build_aggregate_finalfn_expr(), build_aggregate_transfn_expr(), build_coercion_expression(), build_index_pathkeys(), build_index_paths(), build_index_tlist(), build_join_rel(), build_joinrel_tlist(), build_partition_pathkeys(), build_path_tlist(), build_physical_tlist(), build_remote_returning(), build_subplan(), BuildEventTriggerCache(), BuildOnConflictExcludedTargetlist(), buildRelationAliases(), cached_scansel(), calc_joinrel_size_estimate(), check_index_predicates(), check_selective_binary_conversion(), check_sql_fn_retval(), checkInsertTargets(), checkSharedDependencies(), checkWellFormedRecursionWalker(), choose_bitmap_and(), ChooseIndexColumnNames(), classifyConditions(), CloneFkReferenced(), CloneFkReferencing(), CloneRowTriggersToPartition(), coerce_record_to_complex(), compute_common_attribute(), compute_semi_anti_join_factors(), compute_semijoin_info(), ComputeIndexAttrs(), ComputePartitionAttrs(), consider_groupingsets_paths(), consider_new_or_clause(), convert_ANY_sublink_to_join(), convert_EXISTS_to_ANY(), convert_subquery_pathkeys(), ConvertTriggerToFK(), CopyMultiInsertInfoFlush(), CopyMultiInsertInfoSetupBuffer(), create_append_plan(), create_bitmap_scan_plan(), create_bitmap_subplan(), create_ctas_nodata(), create_customscan_plan(), create_degenerate_grouping_paths(), create_groupingsets_plan(), create_hashjoin_plan(), create_index_paths(), create_indexscan_plan(), create_join_clause(), create_list_bounds(), create_merge_append_plan(), create_modifytable_plan(), create_nestloop_path(), create_partitionwise_grouping_paths(), create_tidscan_plan(), create_unique_plan(), database_to_xmlschema_internal(), deconstruct_recurse(), DefineRelation(), DefineSequence(), DefineTSDictionary(), DefineView(), DefineVirtualRelation(), deparseParam(), deparseVar(), deserialize_deflist(), determineRecursiveColTypes(), distribute_qual_to_rels(), distribute_restrictinfo_to_rels(), do_pg_start_backup(), DoCopy(), estimate_multivariate_ndistinct(), estimate_num_groups(), eval_const_expressions_mutator(), EvalPlanQualStart(), EventTriggerAlterTableEnd(), EventTriggerCollectAlterDefPrivs(), EventTriggerCollectAlterOpFam(), EventTriggerCollectAlterTableSubcmd(), EventTriggerCollectAlterTSConfig(), EventTriggerCollectCreateOpClass(), EventTriggerCollectGrant(), EventTriggerCollectSimpleCommand(), Exec_ListenCommit(), ExecAllocTableSlot(), ExecEvalXmlExpr(), ExecGetTriggerResultRel(), ExecInitAlternativeSubPlan(), ExecInitExprList(), ExecInitExprRec(), ExecInitLockRows(), ExecInitModifyTable(), ExecInitNode(), ExecInitPartitionInfo(), ExecInitSubPlan(), ExecPrepareExprList(), ExecSerializePlan(), ExecuteGrantStmt(), ExecuteTruncate(), ExecuteTruncateGuts(), expand_grouping_sets(), expand_groupingset_node(), expand_inherited_rtentry(), expand_single_inheritance_child(), expand_targetlist(), expand_vacuum_rel(), expandRelAttrs(), ExpandRowReference(), expandRTE(), expandTupleDesc(), ExplainNode(), ExportSnapshot(), expression_tree_mutator(), extract_actual_clauses(), extract_actual_join_clauses(), extract_jsp_path_expr_nodes(), extract_lateral_references(), extract_nonindex_conditions(), extract_or_clause(), extract_rollup_sets(), extractRemainingColumns(), fetch_statentries_for_relation(), fetch_table_list(), fetch_upper_rel(), file_fdw_validator(), fill_hba_line(), find_duplicate_ors(), find_hash_columns(), find_indexpath_quals(), find_list_position(), find_mergeclauses_for_outer_pathkeys(), find_minmax_aggs_walker(), find_partition_scheme(), find_placeholder_info(), find_window_functions_walker(), findTargetlistEntrySQL99(), fireRIRrules(), fireRules(), fix_indexorderby_references(), fix_indexqual_references(), flatten_grouping_sets(), flatten_join_alias_vars_mutator(), flatten_join_using_qual(), flatten_simple_union_all(), foreign_grouping_ok(), foreign_join_ok(), format_operator_parts(), format_procedure_parts(), func_get_detail(), gen_partprune_steps_internal(), gen_prune_step_combine(), gen_prune_step_op(), gen_prune_steps_from_opexps(), generate_append_tlist(), generate_bitmap_or_paths(), generate_implied_equalities_for_column(), generate_join_implied_equalities_broken(), generate_join_implied_equalities_normal(), generate_orderedappend_paths(), generate_partitionwise_join_paths(), generate_setop_tlist(), generate_subquery_params(), generate_subquery_vars(), generate_union_paths(), generateClonedExtStatsStmt(), generateClonedIndexStmt(), generateSerialExtraStmts(), get_actual_clauses(), get_all_vacuum_rels(), get_appendrel_parampathinfo(), get_baserel_parampathinfo(), get_database_list(), get_eclass_for_sort_expr(), get_ext_ver_info(), get_ext_ver_list(), get_file_fdw_attribute_options(), get_foreign_key_join_selectivity(), get_func_expr(), get_index_clause_from_support(), get_index_paths(), get_insert_query_def(), get_join_index_paths(), get_joinrel_parampathinfo(), get_op_btree_interpretation(), get_policies_for_relation(), get_qual_for_hash(), get_qual_for_list(), get_qual_for_range(), get_quals_from_indexclauses(), get_range_nulltest(), get_relation_constraints(), get_relation_foreign_keys(), get_relation_statistics(), get_rels_with_domain(), get_required_extension(), get_sortgrouplist_exprs(), get_steps_using_prefix_recurse(), get_subscription_list(), get_switched_clauses(), get_tables_to_cluster(), get_tlist_exprs(), get_update_query_targetlist_def(), get_useful_ecs_for_relation(), get_useful_pathkeys_for_relation(), get_windowfunc_expr(), GetAfterTriggersTableData(), getObjectIdentityParts(), getState(), GetSubscriptionNotReadyRelations(), GetSubscriptionRelations(), gistFindPath(), gistfixsplit(), gistplacetopage(), hash_inner_and_outer(), heap_truncate(), identify_current_nestloop_params(), identify_opfamily_groups(), index_concurrently_create_copy(), infer_arbiter_indexes(), inheritance_planner(), init_execution_state(), init_sql_fcache(), InitPlan(), innerrel_is_unique(), interpret_function_parameter_list(), intorel_startup(), is_innerrel_unique_for(), join_is_removable(), jsonb_ops__extract_nodes(), jsonb_path_ops__extract_nodes(), JsonValueListAppend(), list_append_unique(), list_append_unique_ptr(), list_concat_unique(), list_concat_unique_ptr(), list_difference(), list_difference_ptr(), list_intersection(), list_union(), list_union_ptr(), llvm_compile_module(), load_hba(), load_ident(), LoadPublications(), logicalrep_worker_stop_at_commit(), logicalrep_workers_find(), make_canonical_pathkey(), make_copy_attnamelist(), make_group_input_target(), make_inh_translation_list(), make_inner_pathkeys_for_merge(), make_modifytable(), make_partial_grouping_target(), make_partition_op_expr(), make_partition_pruneinfo(), make_partitionedrel_pruneinfo(), make_pathkeys_for_sortclauses(), make_pathtarget_from_tlist(), make_rel_from_joinlist(), make_row_comparison_op(), make_setop_translation_list(), make_sort_input_target(), make_sub_restrictinfos(), make_tlist_from_pathtarget(), make_window_input_target(), makeDependencyGraphWalker(), match_clause_to_index(), match_clause_to_partition_key(), match_foreign_keys_to_quals(), match_join_clauses_to_index(), match_network_subset(), match_pathkeys_to_index(), match_pattern_prefix(), matchLocks(), merge_clump(), MergeAttributes(), negate_clause(), next_field_expand(), nodeRead(), OpenTableList(), order_qual_clauses(), parse_hba_line(), parseCheckAggregates(), ParseFuncOrColumn(), PartConstraintImpliedByRelConstraint(), perform_base_backup(), pg_get_object_address(), pg_logical_slot_get_changes_guts(), pg_plan_queries(), pg_rewrite_query(), plan_union_children(), postgresAddForeignUpdateTargets(), postgresGetForeignPaths(), postgresGetForeignPlan(), postgresImportForeignSchema(), prep_domain_constraints(), prepare_sort_from_pathkeys(), preprocess_groupclause(), preprocess_grouping_sets(), preprocess_rowmarks(), preprocess_targetlist(), process_duplicate_ors(), process_equivalence(), process_pipe_input(), process_sublinks_mutator(), process_subquery_nestloop_params(), process_syncing_tables_for_apply(), ProcessStartupPacket(), pull_ands(), pull_ors(), pull_up_simple_values(), pull_up_sublinks_jointree_recurse(), pull_up_sublinks_qual_recurse(), pull_up_union_leaf_queries(), pull_var_clause_walker(), pull_vars_walker(), query_tree_mutator(), QueryRewrite(), queue_listen(), range_table_mutator(), read_tablespace_map(), rebuild_fdw_scan_tlist(), RebuildConstraintComment(), record_plan_function_dependency(), record_plan_type_dependency(), reduce_outer_joins_pass1(), register_ENR(), register_label_provider(), ReindexRelationConcurrently(), relation_excluded_by_constraints(), relation_has_unique_index_for(), RelationCacheInvalidate(), RelationGetDummyIndexExpressions(), RelationGetFKeyList(), remap_to_groupclause_idx(), RememberConstraintForRebuilding(), RememberIndexForRebuilding(), RememberSyncRequest(), remove_rel_from_joinlist(), remove_useless_groupby_columns(), RemoveInheritance(), reorder_function_arguments(), reparameterize_path(), reparameterize_path_by_child(), reparameterize_pathlist_by_child(), replace_empty_jointree(), replace_nestloop_param_placeholdervar(), replace_nestloop_param_var(), replace_outer_agg(), replace_outer_grouping(), resolve_unique_index_expr(), RewriteQuery(), rewriteTargetListIU(), rewriteTargetListUD(), rewriteTargetView(), rewriteValuesRTE(), schema_to_xmlschema_internal(), SearchCatCacheList(), select_active_windows(), select_mergejoin_clauses(), select_outer_pathkeys_for_merge(), sepgsql_set_client_label(), sequence_options(), set_append_rel_pathlist(), set_cheapest(), set_deparse_for_query(), set_dummy_tlist_references(), set_plan_references(), set_plan_refs(), set_rtable_names(), set_simple_column_names(), set_subquery_pathlist(), set_upper_references(), set_using_names(), show_eval_params(), show_grouping_set_keys(), show_modifytable_info(), show_plan_tlist(), show_sort_group_keys(), show_tablesample(), simplify_and_arguments(), simplify_or_arguments(), split_pathtarget_at_srfs(), split_pathtarget_walker(), SplitDirectoriesString(), SplitGUCList(), SplitIdentifierString(), SS_make_initplan_from_plan(), SS_process_ctes(), StandbyAcquireAccessExclusiveLock(), statext_mcv_clauselist_selectivity(), StreamServerPort(), stringToQualifiedNameList(), subquery_planner(), table_slot_create(), textarray_to_stringlist(), textarray_to_strvaluelist(), textToQualifiedNameList(), TidExprListCreate(), tokenize_file(), tokenize_inc_file(), transformAExprIn(), transformAggregateCall(), transformAlterTableStmt(), transformArrayExpr(), transformAssignmentIndirection(), transformBoolExpr(), transformCallStmt(), transformCaseExpr(), transformCoalesceExpr(), transformColumnDefinition(), transformContainerSubscripts(), transformCreateSchemaStmt(), transformCreateStmt(), transformDistinctClause(), transformDistinctOnClause(), transformExpressionList(), transformFKConstraints(), transformFkeyGetPrimaryKey(), transformFromClause(), transformFromClauseItem(), transformFuncCall(), transformGenericOptions(), transformGroupClause(), transformGroupClauseExpr(), transformGroupingFunc(), transformGroupingSet(), transformIndexConstraint(), transformIndexConstraints(), transformIndirection(), transformInsertRow(), transformInsertStmt(), transformJoinUsingClause(), transformMinMaxExpr(), transformMultiAssignRef(), transformOfType(), transformPartitionBound(), transformPartitionRangeBounds(), transformPartitionSpec(), transformRangeFunction(), transformRangeTableFunc(), transformRangeTableSample(), transformRowExpr(), transformRuleStmt(), transformSetOperationStmt(), transformSetOperationTree(), transformSubLink(), transformTableConstraint(), transformTableLikeClause(), transformTargetList(), transformValuesClause(), transformWindowDefinitions(), transformWindowFuncCall(), transformWithClause(), transformXmlExpr(), trim_mergeclauses_for_inner_pathkeys(), untransformRelOptions(), UpdateLogicalMappings(), WaitForLockersMultiple(), and xmlelement().

323 {
324  Assert(IsPointerList(list));
325 
326  if (list == NIL)
327  list = new_list(T_List, 1);
328  else
329  new_tail_cell(list);
330 
331  lfirst(list_tail(list)) = datum;
332  check_list_invariants(list);
333  return list;
334 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:76
static void new_tail_cell(List *list)
Definition: list.c:306
#define IsPointerList(l)
Definition: list.c:53
Definition: nodes.h:297
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
static ListCell * list_tail(const List *l)
Definition: pg_list.h:132
static List * new_list(NodeTag type, int min_size)
Definition: list.c:87

◆ lappend_int()

List* lappend_int ( List list,
int  datum 
)

Definition at line 340 of file list.c.

References Assert, check_list_invariants, IsIntegerList, lfirst_int, sort-test::list, list_tail(), new_list(), new_tail_cell(), NIL, and T_IntList.

Referenced by addRangeTableEntryForENR(), addRangeTableEntryForFunction(), analyzeCTETargetList(), ATRewriteTable(), build_subplan(), check_ungrouped_columns_walker(), checkInsertTargets(), convert_EXISTS_to_ANY(), CopyGetAttnums(), deparseAnalyzeSql(), deparseExplicitTargetList(), deparseTargetList(), ExecBuildAggTrans(), ExecBuildGroupingEqual(), ExecInitExprRec(), ExecInitQual(), ExecInitSubscriptingRef(), expand_indexqual_rowcompare(), fetch_statentries_for_relation(), finalize_grouping_exprs_walker(), find_all_inheritors(), find_compatible_peragg(), fix_expr_common(), gen_partprune_steps_internal(), gen_prune_steps_from_opexps(), generate_subquery_params(), inheritance_planner(), list_append_unique_int(), list_concat_unique_int(), list_difference_int(), list_intersection_int(), list_union_int(), match_pathkeys_to_index(), nodeRead(), postgresBeginForeignInsert(), postgresPlanDirectModify(), postgresPlanForeignModify(), rel_is_distinct_for(), remap_to_groupclause_idx(), reorder_grouping_sets(), set_plan_refs(), split_pathtarget_at_srfs(), SS_process_ctes(), SyncRepGetSyncStandbysPriority(), SyncRepGetSyncStandbysQuorum(), TerminateOtherDBBackends(), transformDistinctOnClause(), transformGroupClauseList(), transformInsertStmt(), transformRangeTableFunc(), transformSetOperationTree(), transformValuesClause(), and translate_sub_tlist().

341 {
342  Assert(IsIntegerList(list));
343 
344  if (list == NIL)
345  list = new_list(T_IntList, 1);
346  else
347  new_tail_cell(list);
348 
349  lfirst_int(list_tail(list)) = datum;
350  check_list_invariants(list);
351  return list;
352 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:76
#define IsIntegerList(l)
Definition: list.c:54
#define lfirst_int(lc)
Definition: pg_list.h:191
static void new_tail_cell(List *list)
Definition: list.c:306
#define Assert(condition)
Definition: c.h:739
static ListCell * list_tail(const List *l)
Definition: pg_list.h:132
static List * new_list(NodeTag type, int min_size)
Definition: list.c:87

◆ lappend_oid()

List* lappend_oid ( List list,
Oid  datum 
)

Definition at line 358 of file list.c.

References Assert, check_list_invariants, IsOidList, lfirst_oid, sort-test::list, list_tail(), new_list(), new_tail_cell(), NIL, and T_OidList.

Referenced by add_rte_to_flat_rtable(), addRangeTableEntryForENR(), addRangeTableEntryForFunction(), AfterTriggerSetState(), AlterTableMoveAll(), analyzeCTETargetList(), apply_handle_truncate(), ApplyExtensionUpdates(), assign_collations_walker(), assign_param_for_placeholdervar(), assign_param_for_var(), assign_special_exec_param(), binary_upgrade_create_empty_extension(), check_functional_grouping(), CheckAttributeType(), CloneFkReferenced(), CloneFkReferencing(), compute_semijoin_info(), convert_EXISTS_to_ANY(), create_hashjoin_plan(), create_indexscan_plan(), CreateExtensionInternal(), CreateFunction(), CreateTrigger(), DefineRelation(), do_autovacuum(), EventTriggerCommonSetup(), ExecAlterDefaultPrivilegesStmt(), ExecInitPartitionInfo(), ExecInsertIndexTuples(), ExecuteGrantStmt(), ExecuteTruncate(), ExecuteTruncateGuts(), expand_indexqual_rowcompare(), extract_query_dependencies_walker(), ExtractExtensionList(), find_all_inheritors(), find_inheritance_children(), find_typed_table_dependencies(), fireRIRrules(), fix_expr_common(), generate_new_exec_param(), get_index_ref_constraints(), get_mergejoin_opfamilies(), get_partition_ancestors_worker(), get_steps_using_prefix_recurse(), GetAllTablesPublicationRelations(), GetAllTablesPublications(), getOwnedSequences_internal(), GetParentedForeignKeyRefs(), GetPublicationRelations(), GetRelationPublications(), getRelationsInNamespace(), heap_truncate_check_FKs(), heap_truncate_find_FKs(), index_concurrently_swap(), infer_arbiter_indexes(), inline_function(), list_append_unique_oid(), list_concat_unique_oid(), list_difference_oid(), list_union_oid(), LockViewRecurse(), logicalrep_read_truncate(), make_row_comparison_op(), nodeRead(), objectNamesToOids(), objectsInSchemaToOids(), oid_array_to_list(), OpenTableList(), pgstat_recv_inquiry(), PreCommit_on_commit_actions(), query_to_oid_list(), recomputeNamespacePath(), ReindexMultipleTables(), ReindexRelationConcurrently(), rel_is_distinct_for(), relation_is_updatable(), RelationGetIndexList(), RelationGetStatExtList(), RememberConstraintForRebuilding(), RememberIndexForRebuilding(), remove_dbtablespaces(), remove_useless_groupby_columns(), replace_outer_agg(), replace_outer_grouping(), RestoreReindexState(), roleSpecsToIds(), transformAggregateCall(), transformInsertStmt(), transformRangeTableFunc(), transformSetOperationTree(), transformValuesClause(), TryReuseForeignKey(), and typeInheritsFrom().

359 {
360  Assert(IsOidList(list));
361 
362  if (list == NIL)
363  list = new_list(T_OidList, 1);
364  else
365  new_tail_cell(list);
366 
367  lfirst_oid(list_tail(list)) = datum;
368  check_list_invariants(list);
369  return list;
370 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:76
static void new_tail_cell(List *list)
Definition: list.c:306
#define IsOidList(l)
Definition: list.c:55
#define Assert(condition)
Definition: c.h:739
static ListCell * list_tail(const List *l)
Definition: pg_list.h:132
static List * new_list(NodeTag type, int min_size)
Definition: list.c:87
#define lfirst_oid(lc)
Definition: pg_list.h:192

◆ lcons()

List* lcons ( void *  datum,
List list 
)

Definition at line 454 of file list.c.

References Assert, check_list_invariants, IsPointerList, lfirst, sort-test::list, list_head(), new_head_cell(), new_list(), NIL, and T_List.

Referenced by build_minmax_path(), checkWellFormedRecursionWalker(), consider_groupingsets_paths(), CreateExprContext(), CreateLockFile(), ExecInitModifyTable(), ExplainNode(), extract_rollup_sets(), find_expr_references_walker(), find_update_path(), generate_orderedappend_paths(), generateSerialExtraStmts(), get_name_for_var_field(), get_object_address_rv(), get_query_def(), get_relation_info(), gistEmptyAllBuffers(), gistFindPath(), gistGetNodeBuffer(), gistPushItupToNodeBuffer(), load_domaintype_info(), makeDependencyGraphWalker(), pg_get_object_address(), plan_union_children(), PLy_subtransaction_enter(), PrepareClientEncoding(), push_child_plan(), pushOperator(), PushOverrideSearchPath(), pushStop(), pushValue_internal(), readTimeLineHistory(), register_on_commit_action(), RelationBuildRowSecurity(), RelationCacheInvalidate(), reorder_grouping_sets(), RewriteQuery(), rewriteTargetView(), sepgsql_avc_compute(), set_cheapest(), show_agg_keys(), show_group_keys(), sort_inner_and_outer(), transformCaseExpr(), and UpdateRangeTableOfViewParse().

455 {
456  Assert(IsPointerList(list));
457 
458  if (list == NIL)
459  list = new_list(T_List, 1);
460  else
461  new_head_cell(list);
462 
463  lfirst(list_head(list)) = datum;
464  check_list_invariants(list);
465  return list;
466 }
#define NIL
Definition: pg_list.h:65
static void new_head_cell(List *list)
Definition: list.c:288
#define check_list_invariants(l)
Definition: list.c:76
static ListCell * list_head(const List *l)
Definition: pg_list.h:125
#define IsPointerList(l)
Definition: list.c:53
Definition: nodes.h:297
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
static List * new_list(NodeTag type, int min_size)
Definition: list.c:87

◆ lcons_int()

List* lcons_int ( int  datum,
List list 
)

Definition at line 472 of file list.c.

References Assert, check_list_invariants, IsIntegerList, lfirst_int, sort-test::list, list_head(), new_head_cell(), new_list(), NIL, and T_IntList.

Referenced by ExecInitAgg(), ExplainBeginOutput(), and ExplainOpenGroup().

473 {
474  Assert(IsIntegerList(list));
475 
476  if (list == NIL)
477  list = new_list(T_IntList, 1);
478  else
479  new_head_cell(list);
480 
481  lfirst_int(list_head(list)) = datum;
482  check_list_invariants(list);
483  return list;
484 }
#define NIL
Definition: pg_list.h:65
static void new_head_cell(List *list)
Definition: list.c:288
#define check_list_invariants(l)
Definition: list.c:76
#define IsIntegerList(l)
Definition: list.c:54
#define lfirst_int(lc)
Definition: pg_list.h:191
static ListCell * list_head(const List *l)
Definition: pg_list.h:125
#define Assert(condition)
Definition: c.h:739
static List * new_list(NodeTag type, int min_size)
Definition: list.c:87

◆ lcons_oid()

List* lcons_oid ( Oid  datum,
List list 
)

Definition at line 490 of file list.c.

References Assert, check_list_invariants, IsOidList, lfirst_oid, sort-test::list, list_head(), new_head_cell(), new_list(), NIL, and T_OidList.

Referenced by CreateSchemaCommand(), pg_partition_ancestors(), PushOverrideSearchPath(), recomputeNamespacePath(), and ReindexMultipleTables().

491 {
492  Assert(IsOidList(list));
493 
494  if (list == NIL)
495  list = new_list(T_OidList, 1);
496  else
497  new_head_cell(list);
498 
499  lfirst_oid(list_head(list)) = datum;
500  check_list_invariants(list);
501  return list;
502 }
#define NIL
Definition: pg_list.h:65
static void new_head_cell(List *list)
Definition: list.c:288
#define check_list_invariants(l)
Definition: list.c:76
static ListCell * list_head(const List *l)
Definition: pg_list.h:125
#define IsOidList(l)
Definition: list.c:55
#define Assert(condition)
Definition: c.h:739
static List * new_list(NodeTag type, int min_size)
Definition: list.c:87
#define lfirst_oid(lc)
Definition: pg_list.h:192

◆ list_append_unique()

List* list_append_unique ( List list,
void *  datum 
)

Definition at line 1181 of file list.c.

References lappend(), sort-test::list, and list_member().

Referenced by add_security_quals(), and add_with_check_options().

1182 {
1183  if (list_member(list, datum))
1184  return list;
1185  else
1186  return lappend(list, datum);
1187 }
bool list_member(const List *list, const void *datum)
Definition: list.c:614
List * lappend(List *list, void *datum)
Definition: list.c:322

◆ list_append_unique_int()

List* list_append_unique_int ( List list,
int  datum 
)

Definition at line 1206 of file list.c.

References lappend_int(), sort-test::list, and list_member_int().

1207 {
1208  if (list_member_int(list, datum))
1209  return list;
1210  else
1211  return lappend_int(list, datum);
1212 }
bool list_member_int(const List *list, int datum)
Definition: list.c:655
List * lappend_int(List *list, int datum)
Definition: list.c:340

◆ list_append_unique_oid()

List* list_append_unique_oid ( List list,
Oid  datum 
)

Definition at line 1218 of file list.c.

References lappend_oid(), sort-test::list, and list_member_oid().

Referenced by ATExecAlterConstraint(), btvalidate(), hashvalidate(), is_admin_of_role(), map_sql_typecoll_to_xmlschema_types(), roles_has_privs_of(), and roles_is_member_of().

1219 {
1220  if (list_member_oid(list, datum))
1221  return list;
1222  else
1223  return lappend_oid(list, datum);
1224 }
List * lappend_oid(List *list, Oid datum)
Definition: list.c:358
bool list_member_oid(const List *list, Oid datum)
Definition: list.c:675

◆ list_append_unique_ptr()

List* list_append_unique_ptr ( List list,
void *  datum 
)

Definition at line 1194 of file list.c.

References lappend(), sort-test::list, and list_member_ptr().

Referenced by get_useful_ecs_for_relation(), postgresGetForeignPaths(), subbuild_joinrel_joinlist(), and subbuild_joinrel_restrictlist().

1195 {
1196  if (list_member_ptr(list, datum))
1197  return list;
1198  else
1199  return lappend(list, datum);
1200 }
List * lappend(List *list, void *datum)
Definition: list.c:322
bool list_member_ptr(const List *list, const void *datum)
Definition: list.c:635

◆ list_concat()

List* list_concat ( List list1,
const List list2 
)

Definition at line 516 of file list.c.

References Assert, check_list_invariants, List::elements, enlarge_list(), List::length, list_copy(), List::max_length, NIL, and List::type.

Referenced by accumulate_append_subpath(), add_paths_to_append_rel(), add_predicate_to_index_quals(), addRangeTableEntryForJoin(), addRangeTableEntryForTableFunc(), AtEOSubXact_ApplyLauncher(), ATExecAttachPartition(), ATPostAlterTypeParse(), AtSubCommit_Notify(), build_joinrel_partition_info(), build_joinrel_restrictlist(), build_paths_for_OR(), check_index_predicates(), check_sql_fn_retval(), choose_bitmap_and(), clean_up_removed_plan_level(), consider_groupingsets_paths(), ConstraintImpliedByRelConstraint(), convert_EXISTS_sublink_to_join(), cost_index(), create_append_path(), create_append_plan(), create_bitmap_subplan(), create_index_paths(), create_join_plan(), create_merge_append_plan(), deconstruct_recurse(), DefineRelation(), deparseDirectDeleteSql(), deparseDirectUpdateSql(), deparseFromExprForRel(), estimate_path_cost_size(), expand_groupingset_node(), ExpandAllTables(), expandRTE(), extract_or_clause(), extract_rollup_sets(), fileBeginForeignScan(), fileGetOptions(), find_forced_null_vars(), find_indexpath_quals(), find_mergeclauses_for_outer_pathkeys(), find_nonnullable_vars_walker(), fireRIRrules(), flatten_grouping_sets(), fmgr_sql_validator(), foreign_grouping_ok(), foreign_join_ok(), gen_partprune_steps_internal(), gen_prune_steps_from_opexps(), generate_bitmap_or_paths(), generate_join_implied_equalities(), generate_join_implied_equalities_for_ecs(), generate_join_implied_equalities_normal(), generate_partition_qual(), get_baserel_parampathinfo(), get_foreign_key_join_selectivity(), get_from_clause_item(), get_index_paths(), get_join_index_paths(), get_joinrel_parampathinfo(), get_relation_constraints(), get_rels_with_domain(), get_steps_using_prefix_recurse(), init_sql_fcache(), is_parallel_safe(), objectsInSchemaToOids(), process_equivalence(), process_sublinks_mutator(), pull_ands(), pull_ors(), pull_up_simple_subquery(), pull_up_simple_union_all(), reduce_outer_joins_pass2(), reduce_unique_semijoins(), reorder_grouping_sets(), RewriteQuery(), rewriteRuleAction(), rewriteTargetListIU(), selectColorTrigrams(), set_append_rel_pathlist(), set_plan_refs(), split_pathtarget_at_srfs(), split_pathtarget_walker(), SyncRepGetSyncStandbysPriority(), TidQualFromRestrictInfoList(), transformAExprIn(), transformAlterTableStmt(), transformCreateSchemaStmt(), transformCreateStmt(), transformExpressionList(), transformExtendedStatistics(), transformFromClause(), transformFromClauseItem(), transformIndexConstraints(), transformTargetList(), and vacuum().

517 {
518  int new_len;
519 
520  if (list1 == NIL)
521  return list_copy(list2);
522  if (list2 == NIL)
523  return list1;
524 
525  Assert(list1->type == list2->type);
526 
527  new_len = list1->length + list2->length;
528  /* Enlarge array if necessary */
529  if (new_len > list1->max_length)
530  enlarge_list(list1, new_len);
531 
532  /* Even if list1 == list2, using memcpy should be safe here */
533  memcpy(&list1->elements[list1->length], &list2->elements[0],
534  list2->length * sizeof(ListCell));
535  list1->length = new_len;
536 
537  check_list_invariants(list1);
538  return list1;
539 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:76
List * list_copy(const List *oldlist)
Definition: list.c:1404
static void enlarge_list(List *list, int min_size)
Definition: list.c:153
int max_length
Definition: pg_list.h:54
ListCell * elements
Definition: pg_list.h:55
#define Assert(condition)
Definition: c.h:739
int length
Definition: pg_list.h:53
NodeTag type
Definition: pg_list.h:52

◆ list_concat_copy()

List* list_concat_copy ( const List list1,
const List list2 
)

Definition at line 553 of file list.c.

References Assert, check_list_invariants, List::elements, List::length, list_copy(), new_list(), NIL, and List::type.

Referenced by add_function_defaults(), build_joinrel_partition_info(), build_paths_for_OR(), choose_bitmap_and(), create_scan_plan(), DefineIndex(), gen_partprune_steps(), generate_bitmap_or_paths(), get_parameterized_baserel_size(), make_pathkeys_for_window(), max_parallel_hazard_walker(), process_matched_tle(), simplify_and_arguments(), and simplify_or_arguments().

554 {
555  List *result;
556  int new_len;
557 
558  if (list1 == NIL)
559  return list_copy(list2);
560  if (list2 == NIL)
561  return list_copy(list1);
562 
563  Assert(list1->type == list2->type);
564 
565  new_len = list1->length + list2->length;
566  result = new_list(list1->type, new_len);
567  memcpy(result->elements, list1->elements,
568  list1->length * sizeof(ListCell));
569  memcpy(result->elements + list1->length, list2->elements,
570  list2->length * sizeof(ListCell));
571 
572  check_list_invariants(result);
573  return result;
574 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:76
List * list_copy(const List *oldlist)
Definition: list.c:1404
ListCell * elements
Definition: pg_list.h:55
#define Assert(condition)
Definition: c.h:739
int length
Definition: pg_list.h:53
NodeTag type
Definition: pg_list.h:52
Definition: pg_list.h:50
static List * new_list(NodeTag type, int min_size)
Definition: list.c:87

◆ list_concat_unique()

List* list_concat_unique ( List list1,
const List list2 
)

Definition at line 1238 of file list.c.

References Assert, check_list_invariants, IsPointerList, lappend(), lfirst, and list_member().

Referenced by create_bitmap_subplan(), and select_active_windows().

1239 {
1240  ListCell *cell;
1241 
1242  Assert(IsPointerList(list1));
1243  Assert(IsPointerList(list2));
1244 
1245  foreach(cell, list2)
1246  {
1247  if (!list_member(list1, lfirst(cell)))
1248  list1 = lappend(list1, lfirst(cell));
1249  }
1250 
1251  check_list_invariants(list1);
1252  return list1;
1253 }
#define check_list_invariants(l)
Definition: list.c:76
bool list_member(const List *list, const void *datum)
Definition: list.c:614
#define IsPointerList(l)
Definition: list.c:53
List * lappend(List *list, void *datum)
Definition: list.c:322
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190

◆ list_concat_unique_int()

List* list_concat_unique_int ( List list1,
const List list2 
)

Definition at line 1281 of file list.c.

References Assert, check_list_invariants, IsIntegerList, lappend_int(), lfirst_int, and list_member_int().

1282 {
1283  ListCell *cell;
1284 
1285  Assert(IsIntegerList(list1));
1286  Assert(IsIntegerList(list2));
1287 
1288  foreach(cell, list2)
1289  {
1290  if (!list_member_int(list1, lfirst_int(cell)))
1291  list1 = lappend_int(list1, lfirst_int(cell));
1292  }
1293 
1294  check_list_invariants(list1);
1295  return list1;
1296 }
#define check_list_invariants(l)
Definition: list.c:76
#define IsIntegerList(l)
Definition: list.c:54
#define lfirst_int(lc)
Definition: pg_list.h:191
bool list_member_int(const List *list, int datum)
Definition: list.c:655
List * lappend_int(List *list, int datum)
Definition: list.c:340
#define Assert(condition)
Definition: c.h:739

◆ list_concat_unique_oid()

List* list_concat_unique_oid ( List list1,
const List list2 
)

Definition at line 1302 of file list.c.

References Assert, check_list_invariants, IsOidList, lappend_oid(), lfirst_oid, and list_member_oid().

Referenced by GetRelationPublicationActions().

1303 {
1304  ListCell *cell;
1305 
1306  Assert(IsOidList(list1));
1307  Assert(IsOidList(list2));
1308 
1309  foreach(cell, list2)
1310  {
1311  if (!list_member_oid(list1, lfirst_oid(cell)))
1312  list1 = lappend_oid(list1, lfirst_oid(cell));
1313  }
1314 
1315  check_list_invariants(list1);
1316  return list1;
1317 }
#define check_list_invariants(l)
Definition: list.c:76
List * lappend_oid(List *list, Oid datum)
Definition: list.c:358
#define IsOidList(l)
Definition: list.c:55
bool list_member_oid(const List *list, Oid datum)
Definition: list.c:675
#define Assert(condition)
Definition: c.h:739
#define lfirst_oid(lc)
Definition: pg_list.h:192

◆ list_concat_unique_ptr()

List* list_concat_unique_ptr ( List list1,
const List list2 
)

Definition at line 1260 of file list.c.

References Assert, check_list_invariants, IsPointerList, lappend(), lfirst, and list_member_ptr().

1261 {
1262  ListCell *cell;
1263 
1264  Assert(IsPointerList(list1));
1265  Assert(IsPointerList(list2));
1266 
1267  foreach(cell, list2)
1268  {
1269  if (!list_member_ptr(list1, lfirst(cell)))
1270  list1 = lappend(list1, lfirst(cell));
1271  }
1272 
1273  check_list_invariants(list1);
1274  return list1;
1275 }
#define check_list_invariants(l)
Definition: list.c:76
#define IsPointerList(l)
Definition: list.c:53
List * lappend(List *list, void *datum)
Definition: list.c:322
bool list_member_ptr(const List *list, const void *datum)
Definition: list.c:635
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190

◆ list_copy()

List* list_copy ( const List oldlist)

Definition at line 1404 of file list.c.

References check_list_invariants, List::elements, List::length, new_list(), NIL, and List::type.

Referenced by accumulate_append_subpath(), arrayconst_startup_fn(), arrayexpr_startup_fn(), build_joinrel_partition_info(), build_subplan(), check_index_predicates(), consider_groupingsets_paths(), ConstraintImpliedByRelConstraint(), copy_pathtarget(), copyObjectImpl(), CopyOverrideSearchPath(), create_append_path(), create_append_plan(), create_merge_append_path(), create_merge_append_plan(), does_not_exist_skipping(), EventTriggerCollectGrant(), ExecuteTruncateGuts(), expand_indexqual_rowcompare(), expression_tree_mutator(), fetch_search_path(), generate_mergejoin_paths(), get_eclass_for_sort_expr(), get_foreign_key_join_selectivity(), get_object_address_attrdef(), get_object_address_attribute(), get_object_address_opf_member(), get_object_address_relobject(), get_query_def(), get_required_extension(), get_steps_using_prefix_recurse(), get_switched_clauses(), get_useful_pathkeys_for_relation(), GetOverrideSearchPath(), list_concat(), list_concat_copy(), list_difference(), list_difference_int(), list_difference_oid(), list_difference_ptr(), list_union(), list_union_int(), list_union_oid(), list_union_ptr(), owningrel_does_not_exist_skipping(), process_owned_by(), PushOverrideSearchPath(), recomputeNamespacePath(), RelationGetIndexList(), RelationGetStatExtList(), remove_rel_from_query(), reorder_grouping_sets(), roles_has_privs_of(), roles_is_member_of(), select_active_windows(), select_outer_pathkeys_for_merge(), set_using_names(), SetReindexPending(), simplify_and_arguments(), simplify_or_arguments(), sort_inner_and_outer(), transformWithClause(), and truncate_useless_pathkeys().

1405 {
1406  List *newlist;
1407 
1408  if (oldlist == NIL)
1409  return NIL;
1410 
1411  newlist = new_list(oldlist->type, oldlist->length);
1412  memcpy(newlist->elements, oldlist->elements,
1413  newlist->length * sizeof(ListCell));
1414 
1415  check_list_invariants(newlist);
1416  return newlist;
1417 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:76
ListCell * elements
Definition: pg_list.h:55
int length
Definition: pg_list.h:53
NodeTag type
Definition: pg_list.h:52
Definition: pg_list.h:50
static List * new_list(NodeTag type, int min_size)
Definition: list.c:87

◆ list_copy_deep()

List* list_copy_deep ( const List oldlist)

Definition at line 1449 of file list.c.

References Assert, check_list_invariants, copyObjectImpl(), List::elements, i, IsA, List::length, lfirst, new_list(), NIL, and List::type.

Referenced by copyObjectImpl().

1450 {
1451  List *newlist;
1452 
1453  if (oldlist == NIL)
1454  return NIL;
1455 
1456  /* This is only sensible for pointer Lists */
1457  Assert(IsA(oldlist, List));
1458 
1459  newlist = new_list(oldlist->type, oldlist->length);
1460  for (int i = 0; i < newlist->length; i++)
1461  lfirst(&newlist->elements[i]) =
1462  copyObjectImpl(lfirst(&oldlist->elements[i]));
1463 
1464  check_list_invariants(newlist);
1465  return newlist;
1466 }
#define NIL
Definition: pg_list.h:65
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
#define check_list_invariants(l)
Definition: list.c:76
ListCell * elements
Definition: pg_list.h:55
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
int length
Definition: pg_list.h:53
NodeTag type
Definition: pg_list.h:52
int i
Definition: pg_list.h:50
static List * new_list(NodeTag type, int min_size)
Definition: list.c:87
void * copyObjectImpl(const void *from)
Definition: copyfuncs.c:4760

◆ list_copy_tail()

List* list_copy_tail ( const List oldlist,
int  nskip 
)

Definition at line 1423 of file list.c.

References check_list_invariants, List::elements, List::length, new_list(), NIL, and List::type.

Referenced by accumulate_append_subpath(), add_function_defaults(), addRangeTableEntryForJoin(), addRangeTableEntryForTableFunc(), does_not_exist_skipping(), expandRTE(), find_expr_references_walker(), func_get_detail(), get_name_for_var_field(), get_object_address_opcf(), ParseFuncOrColumn(), push_ancestor_plan(), and transformAggregateCall().

1424 {
1425  List *newlist;
1426 
1427  if (nskip < 0)
1428  nskip = 0; /* would it be better to elog? */
1429 
1430  if (oldlist == NIL || nskip >= oldlist->length)
1431  return NIL;
1432 
1433  newlist = new_list(oldlist->type, oldlist->length - nskip);
1434  memcpy(newlist->elements, &oldlist->elements[nskip],
1435  newlist->length * sizeof(ListCell));
1436 
1437  check_list_invariants(newlist);
1438  return newlist;
1439 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:76
ListCell * elements
Definition: pg_list.h:55
int length
Definition: pg_list.h:53
NodeTag type
Definition: pg_list.h:52
Definition: pg_list.h:50
static List * new_list(NodeTag type, int min_size)
Definition: list.c:87

◆ list_deduplicate_oid()

void list_deduplicate_oid ( List list)

Definition at line 1326 of file list.c.

References Assert, check_list_invariants, List::elements, i, IsOidList, List::length, list_length(), and ListCell::oid_value.

Referenced by heap_truncate_find_FKs().

1327 {
1328  int len;
1329 
1330  Assert(IsOidList(list));
1331  len = list_length(list);
1332  if (len > 1)
1333  {
1334  ListCell *elements = list->elements;
1335  int i = 0;
1336 
1337  for (int j = 1; j < len; j++)
1338  {
1339  if (elements[i].oid_value != elements[j].oid_value)
1340  elements[++i].oid_value = elements[j].oid_value;
1341  }
1342  list->length = i + 1;
1343  }
1344  check_list_invariants(list);
1345 }
#define check_list_invariants(l)
Definition: list.c:76
ListCell * elements
Definition: pg_list.h:55
#define IsOidList(l)
Definition: list.c:55
#define Assert(condition)
Definition: c.h:739
static int list_length(const List *l)
Definition: pg_list.h:169
int length
Definition: pg_list.h:53
Oid oid_value
Definition: pg_list.h:47
int i

◆ list_delete()

List* list_delete ( List list,
void *  datum 
)

Definition at line 778 of file list.c.

References Assert, check_list_invariants, equal(), IsPointerList, lfirst, sort-test::list, and list_delete_cell().

Referenced by postgresGetForeignPlan(), and unregister_ENR().

779 {
780  ListCell *cell;
781 
782  Assert(IsPointerList(list));
783  check_list_invariants(list);
784 
785  foreach(cell, list)
786  {
787  if (equal(lfirst(cell), datum))
788  return list_delete_cell(list, cell);
789  }
790 
791  /* Didn't find a match: return the list unmodified */
792  return list;
793 }
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:3011
#define check_list_invariants(l)
Definition: list.c:76
#define IsPointerList(l)
Definition: list.c:53
List * list_delete_cell(List *list, ListCell *cell)
Definition: list.c:768
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190

◆ list_delete_cell()

List* list_delete_cell ( List list,
ListCell cell 
)

Definition at line 768 of file list.c.

References List::elements, and list_delete_nth_cell().

Referenced by list_delete(), list_delete_int(), list_delete_oid(), list_delete_ptr(), remove_useless_joins(), and transformGenericOptions().

769 {
770  return list_delete_nth_cell(list, cell - list->elements);
771 }
ListCell * elements
Definition: pg_list.h:55
List * list_delete_nth_cell(List *list, int n)
Definition: list.c:697

◆ list_delete_first()

◆ list_delete_int()

List* list_delete_int ( List list,
int  datum 
)

Definition at line 816 of file list.c.

References Assert, check_list_invariants, IsIntegerList, lfirst_int, sort-test::list, and list_delete_cell().

Referenced by reorder_grouping_sets().

817 {
818  ListCell *cell;
819 
820  Assert(IsIntegerList(list));
821  check_list_invariants(list);
822 
823  foreach(cell, list)
824  {
825  if (lfirst_int(cell) == datum)
826  return list_delete_cell(list, cell);
827  }
828 
829  /* Didn't find a match: return the list unmodified */
830  return list;
831 }
#define check_list_invariants(l)
Definition: list.c:76
#define IsIntegerList(l)
Definition: list.c:54
#define lfirst_int(lc)
Definition: pg_list.h:191
List * list_delete_cell(List *list, ListCell *cell)
Definition: list.c:768
#define Assert(condition)
Definition: c.h:739

◆ list_delete_last()

List* list_delete_last ( List list)

Definition at line 878 of file list.c.

References check_list_invariants, list_free(), list_length(), list_truncate(), and NIL.

Referenced by CheckAttributeType(), fireRIRrules(), inline_function(), LockViewRecurse(), relation_is_updatable(), and RewriteQuery().

879 {
880  check_list_invariants(list);
881 
882  if (list == NIL)
883  return NIL; /* would an error be better? */
884 
885  /* list_truncate won't free list if it goes to empty, but this should */
886  if (list_length(list) <= 1)
887  {
888  list_free(list);
889  return NIL;
890  }
891 
892  return list_truncate(list, list_length(list) - 1);
893 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:76
List * list_truncate(List *list, int new_size)
Definition: list.c:586
static int list_length(const List *l)
Definition: pg_list.h:169
void list_free(List *list)
Definition: list.c:1377

◆ list_delete_nth_cell()

List* list_delete_nth_cell ( List list,
int  n 
)

Definition at line 697 of file list.c.

References Assert, check_list_invariants, List::elements, GetMemoryChunkContext(), List::initial_elements, List::length, sort-test::list, list_free(), List::max_length, memmove, MemoryContextAlloc(), NIL, pfree(), and VALGRIND_MAKE_MEM_NOACCESS.

Referenced by list_delete_cell(), list_delete_first(), and MergeAttributes().

698 {
699  check_list_invariants(list);
700 
701  Assert(n >= 0 && n < list->length);
702 
703  /*
704  * If we're about to delete the last node from the list, free the whole
705  * list instead and return NIL, which is the only valid representation of
706  * a zero-length list.
707  */
708  if (list->length == 1)
709  {
710  list_free(list);
711  return NIL;
712  }
713 
714  /*
715  * Otherwise, we normally just collapse out the removed element. But for
716  * debugging purposes, move the whole list contents someplace else.
717  *
718  * (Note that we *must* keep the contents in the same memory context.)
719  */
720 #ifndef DEBUG_LIST_MEMORY_USAGE
721  memmove(&list->elements[n], &list->elements[n + 1],
722  (list->length - 1 - n) * sizeof(ListCell));
723  list->length--;
724 #else
725  {
726  ListCell *newelems;
727  int newmaxlen = list->length - 1;
728 
729  newelems = (ListCell *)
731  newmaxlen * sizeof(ListCell));
732  memcpy(newelems, list->elements, n * sizeof(ListCell));
733  memcpy(&newelems[n], &list->elements[n + 1],
734  (list->length - 1 - n) * sizeof(ListCell));
735  if (list->elements != list->initial_elements)
736  pfree(list->elements);
737  else
738  {
739  /*
740  * As in enlarge_list(), clear the initial_elements[] space and/or
741  * mark it inaccessible.
742  */
743 #ifdef CLOBBER_FREED_MEMORY
744  wipe_mem(list->initial_elements,
745  list->max_length * sizeof(ListCell));
746 #else
748  list->max_length * sizeof(ListCell));
749 #endif
750  }
751  list->elements = newelems;
752  list->max_length = newmaxlen;
753  list->length--;
754  check_list_invariants(list);
755  }
756 #endif
757 
758  return list;
759 }
#define NIL
Definition: pg_list.h:65
#define VALGRIND_MAKE_MEM_NOACCESS(addr, size)
Definition: memdebug.h:27
#define check_list_invariants(l)
Definition: list.c:76
void pfree(void *pointer)
Definition: mcxt.c:1056
#define memmove(d, s, c)
Definition: c.h:1267
union ListCell ListCell
int max_length
Definition: pg_list.h:54
ListCell * elements
Definition: pg_list.h:55
#define Assert(condition)
Definition: c.h:739
int length
Definition: pg_list.h:53
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:796
void list_free(List *list)
Definition: list.c:1377
ListCell initial_elements[FLEXIBLE_ARRAY_MEMBER]
Definition: pg_list.h:57
static MemoryContext GetMemoryChunkContext(void *pointer)
Definition: memutils.h:113

◆ list_delete_oid()

List* list_delete_oid ( List list,
Oid  datum 
)

Definition at line 835 of file list.c.

References Assert, check_list_invariants, IsOidList, lfirst_oid, sort-test::list, and list_delete_cell().

Referenced by RemoveReindexPending().

836 {
837  ListCell *cell;
838 
839  Assert(IsOidList(list));
840  check_list_invariants(list);
841 
842  foreach(cell, list)
843  {
844  if (lfirst_oid(cell) == datum)
845  return list_delete_cell(list, cell);
846  }
847 
848  /* Didn't find a match: return the list unmodified */
849  return list;
850 }
#define check_list_invariants(l)
Definition: list.c:76
List * list_delete_cell(List *list, ListCell *cell)
Definition: list.c:768
#define IsOidList(l)
Definition: list.c:55
#define Assert(condition)
Definition: c.h:739
#define lfirst_oid(lc)
Definition: pg_list.h:192

◆ list_delete_ptr()

List* list_delete_ptr ( List list,
void *  datum 
)

Definition at line 797 of file list.c.

References Assert, check_list_invariants, IsPointerList, lfirst, sort-test::list, and list_delete_cell().

Referenced by adjustJoinTreeList(), ConvertTriggerToFK(), FreeExprContext(), generateSerialExtraStmts(), process_equivalence(), reconsider_full_join_clause(), remove_join_clause_from_rels(), sort_inner_and_outer(), and transformMultiAssignRef().

798 {
799  ListCell *cell;
800 
801  Assert(IsPointerList(list));
802  check_list_invariants(list);
803 
804  foreach(cell, list)
805  {
806  if (lfirst(cell) == datum)
807  return list_delete_cell(list, cell);
808  }
809 
810  /* Didn't find a match: return the list unmodified */
811  return list;
812 }
#define check_list_invariants(l)
Definition: list.c:76
#define IsPointerList(l)
Definition: list.c:53
List * list_delete_cell(List *list, ListCell *cell)
Definition: list.c:768
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190

◆ list_difference()

List* list_difference ( const List list1,
const List list2 
)

Definition at line 1077 of file list.c.

References Assert, check_list_invariants, IsPointerList, lappend(), lfirst, list_copy(), list_member(), and NIL.

Referenced by create_hashjoin_plan(), create_mergejoin_plan(), create_tidscan_plan(), infer_arbiter_indexes(), and process_duplicate_ors().

1078 {
1079  const ListCell *cell;
1080  List *result = NIL;
1081 
1082  Assert(IsPointerList(list1));
1083  Assert(IsPointerList(list2));
1084 
1085  if (list2 == NIL)
1086  return list_copy(list1);
1087 
1088  foreach(cell, list1)
1089  {
1090  if (!list_member(list2, lfirst(cell)))
1091  result = lappend(result, lfirst(cell));
1092  }
1093 
1094  check_list_invariants(result);
1095  return result;
1096 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:76
List * list_copy(const List *oldlist)
Definition: list.c:1404
bool list_member(const List *list, const void *datum)
Definition: list.c:614
#define IsPointerList(l)
Definition: list.c:53
List * lappend(List *list, void *datum)
Definition: list.c:322
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
Definition: pg_list.h:50

◆ list_difference_int()

List* list_difference_int ( const List list1,
const List list2 
)

Definition at line 1128 of file list.c.

References Assert, check_list_invariants, IsIntegerList, lappend_int(), lfirst_int, list_copy(), list_member_int(), and NIL.

Referenced by reorder_grouping_sets().

1129 {
1130  const ListCell *cell;
1131  List *result = NIL;
1132 
1133  Assert(IsIntegerList(list1));
1134  Assert(IsIntegerList(list2));
1135 
1136  if (list2 == NIL)
1137  return list_copy(list1);
1138 
1139  foreach(cell, list1)
1140  {
1141  if (!list_member_int(list2, lfirst_int(cell)))
1142  result = lappend_int(result, lfirst_int(cell));
1143  }
1144 
1145  check_list_invariants(result);
1146  return result;
1147 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:76
List * list_copy(const List *oldlist)
Definition: list.c:1404
#define IsIntegerList(l)
Definition: list.c:54
#define lfirst_int(lc)
Definition: pg_list.h:191
bool list_member_int(const List *list, int datum)
Definition: list.c:655
List * lappend_int(List *list, int datum)
Definition: list.c:340
#define Assert(condition)
Definition: c.h:739
Definition: pg_list.h:50

◆ list_difference_oid()

List* list_difference_oid ( const List list1,
const List list2 
)

Definition at line 1153 of file list.c.

References Assert, check_list_invariants, IsOidList, lappend_oid(), lfirst_oid, list_copy(), list_member_oid(), and NIL.

1154 {
1155  const ListCell *cell;
1156  List *result = NIL;
1157 
1158  Assert(IsOidList(list1));
1159  Assert(IsOidList(list2));
1160 
1161  if (list2 == NIL)
1162  return list_copy(list1);
1163 
1164  foreach(cell, list1)
1165  {
1166  if (!list_member_oid(list2, lfirst_oid(cell)))
1167  result = lappend_oid(result, lfirst_oid(cell));
1168  }
1169 
1170  check_list_invariants(result);
1171  return result;
1172 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:76
List * list_copy(const List *oldlist)
Definition: list.c:1404
List * lappend_oid(List *list, Oid datum)
Definition: list.c:358
#define IsOidList(l)
Definition: list.c:55
bool list_member_oid(const List *list, Oid datum)
Definition: list.c:675
#define Assert(condition)
Definition: c.h:739
Definition: pg_list.h:50
#define lfirst_oid(lc)
Definition: pg_list.h:192

◆ list_difference_ptr()

List* list_difference_ptr ( const List list1,
const List list2 
)

Definition at line 1103 of file list.c.

References Assert, check_list_invariants, IsPointerList, lappend(), lfirst, list_copy(), list_member_ptr(), and NIL.

Referenced by create_bitmap_scan_plan(), and ExecuteTruncateGuts().

1104 {
1105  const ListCell *cell;
1106  List *result = NIL;
1107 
1108  Assert(IsPointerList(list1));
1109  Assert(IsPointerList(list2));
1110 
1111  if (list2 == NIL)
1112  return list_copy(list1);
1113 
1114  foreach(cell, list1)
1115  {
1116  if (!list_member_ptr(list2, lfirst(cell)))
1117  result = lappend(result, lfirst(cell));
1118  }
1119 
1120  check_list_invariants(result);
1121  return result;
1122 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:76
List * list_copy(const List *oldlist)
Definition: list.c:1404
#define IsPointerList(l)
Definition: list.c:53
List * lappend(List *list, void *datum)
Definition: list.c:322
bool list_member_ptr(const List *list, const void *datum)
Definition: list.c:635
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
Definition: pg_list.h:50

◆ list_free()

void list_free ( List list)

Definition at line 1377 of file list.c.

References list_free_private().

Referenced by AfterTriggerSetState(), AlterIndexNamespaces(), arrayconst_cleanup_fn(), arrayexpr_cleanup_fn(), ATCheckPartitionsNotInUse(), AtEOSubXact_Namespace(), AtEOXact_Namespace(), ATExecChangeOwner(), ATExecDropNotNull(), ATExecSetTableSpace(), build_base_rel_tlists(), build_remote_returning(), calc_joinrel_size_estimate(), calculate_indexes_size(), calculate_toast_table_size(), check_datestyle(), check_log_destination(), check_search_path(), check_temp_tablespaces(), check_wal_consistency_checking(), choose_bitmap_and(), compute_semi_anti_join_factors(), CopyFrom(), CopyMultiInsertBufferFlush(), CopyMultiInsertInfoCleanup(), CreateExtensionInternal(), CreateTrigger(), current_schema(), current_schemas(), DefineIndex(), DefineRelation(), distribute_qual_to_rels(), DropSubscription(), EventTriggerDDLCommandEnd(), EventTriggerDDLCommandStart(), EventTriggerSQLDrop(), EventTriggerTableRewrite(), ExecInitPartitionInfo(), ExecInsert(), ExecOpenIndices(), ExecRefreshMatView(), ExecResetTupleTable(), ExecSimpleRelationInsert(), ExecSimpleRelationUpdate(), ExecUpdate(), extract_lateral_references(), ExtractExtensionList(), find_all_inheritors(), find_compatible_peragg(), find_expr_references_walker(), find_hash_columns(), find_placeholders_in_expr(), fix_placeholder_input_needed_levels(), generate_base_implied_equalities_no_const(), generate_partitionwise_join_paths(), get_rel_sync_entry(), get_relation_info(), get_relation_statistics(), get_steps_using_prefix_recurse(), index_concurrently_swap(), index_get_partition(), infer_arbiter_indexes(), is_admin_of_role(), list_delete_last(), list_delete_nth_cell(), make_group_input_target(), make_partial_grouping_target(), make_pathkeys_for_window(), make_sort_input_target(), make_window_input_target(), max_parallel_hazard_walker(), OpenTableList(), parse_hba_auth_opt(), pg_partition_root(), pgstat_write_statsfiles(), plpgsql_extra_checks_check_hook(), pop_ancestor_plan(), PopOverrideSearchPath(), PostmasterMain(), prepare_sort_from_pathkeys(), PrepareTempTablespaces(), preprocess_targetlist(), ProcessUtilitySlow(), qual_is_pushdown_safe(), recomputeNamespacePath(), refresh_by_match_merge(), RelationCacheInvalidate(), RelationDestroyRelation(), RelationGetIndexAttrBitmap(), RelationGetIndexList(), RelationGetPrimaryKeyIndex(), RelationGetReplicaIndex(), RelationGetStatExtList(), relationHasPrimaryKey(), remove_dbtablespaces(), reorder_grouping_sets(), reparameterize_pathlist_by_child(), roles_has_privs_of(), roles_is_member_of(), sepgsql_dml_privileges(), simplify_and_arguments(), simplify_or_arguments(), stringToQualifiedNameList(), SyncRepGetSyncRecPtr(), SyncRepGetSyncStandbysPriority(), textToQualifiedNameList(), toast_open_indexes(), transformFkeyCheckAttrs(), transformFkeyGetPrimaryKey(), transformTableLikeClause(), transformValuesClause(), triggered_change_notification(), typeInheritsFrom(), vac_open_indexes(), and WaitForLockers().

1378 {
1379  list_free_private(list, false);
1380 }
static void list_free_private(List *list, bool deep)
Definition: list.c:1351

◆ list_free_deep()

void list_free_deep ( List list)

Definition at line 1391 of file list.c.

References Assert, IsPointerList, and list_free_private().

Referenced by AfterTriggerFreeQuery(), AtEOSubXact_ApplyLauncher(), ATExecDetachPartition(), checkSharedDependencies(), Exec_UnlistenAllCommit(), FreeSubscription(), get_rel_sync_entry(), gistbufferinginserttuples(), load_libraries(), lookup_proof_cache(), PostmasterMain(), process_syncing_tables_for_apply(), RelationDestroyRelation(), RelationGetFKeyList(), rescanLatestTimeLine(), StartReplication(), WaitForLockersMultiple(), XLogReadDetermineTimeline(), and XLogSendPhysical().

1392 {
1393  /*
1394  * A "deep" free operation only makes sense on a list of pointers.
1395  */
1396  Assert(IsPointerList(list));
1397  list_free_private(list, true);
1398 }
#define IsPointerList(l)
Definition: list.c:53
#define Assert(condition)
Definition: c.h:739
static void list_free_private(List *list, bool deep)
Definition: list.c:1351

◆ list_free_private()

static void list_free_private ( List list,
bool  deep 
)
static

Definition at line 1351 of file list.c.

References check_list_invariants, List::elements, i, List::initial_elements, List::length, lfirst, NIL, and pfree().

Referenced by list_free(), and list_free_deep().

1352 {
1353  if (list == NIL)
1354  return; /* nothing to do */
1355 
1356  check_list_invariants(list);
1357 
1358  if (deep)
1359  {
1360  for (int i = 0; i < list->length; i++)
1361  pfree(lfirst(&list->elements[i]));
1362  }
1363  if (list->elements != list->initial_elements)
1364  pfree(list->elements);
1365  pfree(list);
1366 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:76
void pfree(void *pointer)
Definition: mcxt.c:1056
ListCell * elements
Definition: pg_list.h:55
#define lfirst(lc)
Definition: pg_list.h:190
int length
Definition: pg_list.h:53
int i
ListCell initial_elements[FLEXIBLE_ARRAY_MEMBER]
Definition: pg_list.h:57

◆ list_insert_nth()

List* list_insert_nth ( List list,
int  pos,
void *  datum 
)

Definition at line 401 of file list.c.

References Assert, check_list_invariants, insert_new_cell(), IsPointerList, lfirst, sort-test::list, list_make1, and NIL.

Referenced by add_partial_path(), add_path(), and merge_clump().

402 {
403  if (list == NIL)
404  {
405  Assert(pos == 0);
406  return list_make1(datum);
407  }
408  Assert(IsPointerList(list));
409  lfirst(insert_new_cell(list, pos)) = datum;
410  check_list_invariants(list);
411  return list;
412 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:76
static ListCell * insert_new_cell(List *list, int pos)
Definition: list.c:380
#define list_make1(x1)
Definition: pg_list.h:227
#define IsPointerList(l)
Definition: list.c:53
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190

◆ list_insert_nth_int()

List* list_insert_nth_int ( List list,
int  pos,
int  datum 
)

Definition at line 415 of file list.c.

References Assert, check_list_invariants, insert_new_cell(), IsIntegerList, lfirst_int, sort-test::list, list_make1_int, and NIL.

416 {
417  if (list == NIL)
418  {
419  Assert(pos == 0);
420  return list_make1_int(datum);
421  }
422  Assert(IsIntegerList(list));
423  lfirst_int(insert_new_cell(list, pos)) = datum;
424  check_list_invariants(list);
425  return list;
426 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:76
static ListCell * insert_new_cell(List *list, int pos)
Definition: list.c:380
#define IsIntegerList(l)
Definition: list.c:54
#define lfirst_int(lc)
Definition: pg_list.h:191
#define list_make1_int(x1)
Definition: pg_list.h:238
#define Assert(condition)
Definition: c.h:739

◆ list_insert_nth_oid()

List* list_insert_nth_oid ( List list,
int  pos,
Oid  datum 
)

Definition at line 429 of file list.c.

References Assert, check_list_invariants, insert_new_cell(), IsOidList, lfirst_oid, sort-test::list, list_make1_oid, and NIL.

430 {
431  if (list == NIL)
432  {
433  Assert(pos == 0);
434  return list_make1_oid(datum);
435  }
436  Assert(IsOidList(list));
437  lfirst_oid(insert_new_cell(list, pos)) = datum;
438  check_list_invariants(list);
439  return list;
440 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:76
static ListCell * insert_new_cell(List *list, int pos)
Definition: list.c:380
#define list_make1_oid(x1)
Definition: pg_list.h:249
#define IsOidList(l)
Definition: list.c:55
#define Assert(condition)
Definition: c.h:739
#define lfirst_oid(lc)
Definition: pg_list.h:192

◆ list_intersection()

List* list_intersection ( const List list1,
const List list2 
)

Definition at line 1019 of file list.c.

References Assert, check_list_invariants, IsPointerList, lappend(), lfirst, list_member(), and NIL.

Referenced by find_nonnullable_vars_walker(), and reduce_outer_joins_pass2().

1020 {
1021  List *result;
1022  const ListCell *cell;
1023 
1024  if (list1 == NIL || list2 == NIL)
1025  return NIL;
1026 
1027  Assert(IsPointerList(list1));
1028  Assert(IsPointerList(list2));
1029 
1030  result = NIL;
1031  foreach(cell, list1)
1032  {
1033  if (list_member(list2, lfirst(cell)))
1034  result = lappend(result, lfirst(cell));
1035  }
1036 
1037  check_list_invariants(result);
1038  return result;
1039 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:76
bool list_member(const List *list, const void *datum)
Definition: list.c:614
#define IsPointerList(l)
Definition: list.c:53
List * lappend(List *list, void *datum)
Definition: list.c:322
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
Definition: pg_list.h:50

◆ list_intersection_int()

List* list_intersection_int ( const List list1,
const List list2 
)

Definition at line 1045 of file list.c.

References Assert, check_list_invariants, IsIntegerList, lappend_int(), lfirst_int, list_member_int(), and NIL.

Referenced by parseCheckAggregates().

1046 {
1047  List *result;
1048  const ListCell *cell;
1049 
1050  if (list1 == NIL || list2 == NIL)
1051  return NIL;
1052 
1053  Assert(IsIntegerList(list1));
1054  Assert(IsIntegerList(list2));
1055 
1056  result = NIL;
1057  foreach(cell, list1)
1058  {
1059  if (list_member_int(list2, lfirst_int(cell)))
1060  result = lappend_int(result, lfirst_int(cell));
1061  }
1062 
1063  check_list_invariants(result);
1064  return result;
1065 }
#define NIL
Definition: pg_list.h:65
#define check_list_invariants(l)
Definition: list.c:76
#define IsIntegerList(l)
Definition: list.c:54
#define lfirst_int(lc)
Definition: pg_list.h:191
bool list_member_int(const List *list, int datum)
Definition: list.c:655
List * lappend_int(List *list, int datum)
Definition: list.c:340
#define Assert(condition)
Definition: c.h:739
Definition: pg_list.h:50

◆ list_make1_impl()

List* list_make1_impl ( NodeTag  t,
ListCell  datum1 
)

Definition at line 234 of file list.c.

References check_list_invariants, List::elements, sort-test::list, and new_list().

235 {
236  List *list = new_list(t, 1);
237 
238  list->elements[0] = datum1;
239  check_list_invariants(list);
240  return list;
241 }
#define check_list_invariants(l)
Definition: list.c:76
ListCell * elements
Definition: pg_list.h:55
Definition: pg_list.h:50
static List * new_list(NodeTag type, int min_size)
Definition: list.c:87

◆ list_make2_impl()

List* list_make2_impl ( NodeTag  t,
ListCell  datum1,
ListCell  datum2 
)

Definition at line 244 of file list.c.

References check_list_invariants, List::elements, sort-test::list, and new_list().

245 {
246  List *list = new_list(t, 2);
247 
248  list->elements[0] = datum1;
249  list->elements[1] = datum2;
250  check_list_invariants(list);
251  return list;
252 }
#define check_list_invariants(l)
Definition: list.c:76
ListCell * elements
Definition: pg_list.h:55
Definition: pg_list.h:50
static List * new_list(NodeTag type, int min_size)
Definition: list.c:87

◆ list_make3_impl()

List* list_make3_impl ( NodeTag  t,
ListCell  datum1,
ListCell  datum2,
ListCell  datum3 
)

Definition at line 255 of file list.c.

References check_list_invariants, List::elements, sort-test::list, and new_list().

257 {
258  List *list = new_list(t, 3);
259 
260  list->elements[0] = datum1;
261  list->elements[1] = datum2;
262  list->elements[2] = datum3;
263  check_list_invariants(list);
264  return list;
265 }
#define check_list_invariants(l)
Definition: list.c:76
ListCell * elements
Definition: pg_list.h:55
Definition: pg_list.h:50
static List * new_list(NodeTag type, int min_size)
Definition: list.c:87

◆ list_make4_impl()

List* list_make4_impl ( NodeTag  t,
ListCell  datum1,
ListCell  datum2,
ListCell  datum3,
ListCell  datum4 
)

Definition at line 268 of file list.c.

References check_list_invariants, List::elements, sort-test::list, and new_list().

270 {
271  List *list = new_list(t, 4);
272 
273  list->elements[0] = datum1;
274  list->elements[1] = datum2;
275  list->elements[2] = datum3;
276  list->elements[3] = datum4;
277  check_list_invariants(list);
278  return list;
279 }
#define check_list_invariants(l)
Definition: list.c:76
ListCell * elements
Definition: pg_list.h:55
Definition: pg_list.h:50
static List * new_list(NodeTag type, int min_size)
Definition: list.c:87

◆ list_member()

bool list_member ( const List list,
const void *  datum 
)

Definition at line 614 of file list.c.

References Assert, check_list_invariants, equal(), IsPointerList, and lfirst.

Referenced by add_new_column_to_pathtarget(), build_minmax_path(), create_bitmap_scan_plan(), ec_member_matches_foreign(), find_window_functions_walker(), group_by_has_partkey(), infer_arbiter_indexes(), list_append_unique(), list_concat_unique(), list_difference(), list_intersection(), list_union(), process_duplicate_ors(), split_pathtarget_at_srfs(), and split_pathtarget_walker().

615 {
616  const ListCell *cell;
617 
618  Assert(IsPointerList(list));
619  check_list_invariants(list);
620 
621  foreach(cell, list)
622  {
623  if (equal(lfirst(cell), datum))
624  return true;
625  }
626 
627  return false;
628 }
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:3011
#define check_list_invariants(l)
Definition: list.c:76
#define IsPointerList(l)
Definition: list.c:53
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190

◆ list_member_int()

bool list_member_int ( const List list,
int  datum 
)

Definition at line 655 of file list.c.

References Assert, check_list_invariants, IsIntegerList, and lfirst_int.

Referenced by BeginCopy(), BeginCopyFrom(), check_ungrouped_columns_walker(), CopyGetAttnums(), estimate_num_groups(), init_returning_filter(), list_append_unique_int(), list_concat_unique_int(), list_difference_int(), list_intersection_int(), list_union_int(), max_parallel_hazard_walker(), parseCheckAggregates(), pg_stat_get_wal_senders(), reorder_grouping_sets(), and transformDistinctOnClause().

656 {
657  const ListCell *cell;
658 
659  Assert(IsIntegerList(list));
660  check_list_invariants(list);
661 
662  foreach(cell, list)
663  {
664  if (lfirst_int(cell) == datum)
665  return true;
666  }
667 
668  return false;
669 }
#define check_list_invariants(l)
Definition: list.c:76
#define IsIntegerList(l)
Definition: list.c:54
#define lfirst_int(lc)
Definition: pg_list.h:191
#define Assert(condition)
Definition: c.h:739

◆ list_member_oid()

bool list_member_oid ( const List list,
Oid  datum 
)

Definition at line 675 of file list.c.

References Assert, check_list_invariants, IsOidList, and lfirst_oid.

Referenced by AfterTriggerSaveEvent(), AlterTableMoveAll(), ATExecAddInherit(), ATExecAttachPartition(), BeginCopy(), CheckAttributeType(), CloneFkReferencing(), CollationIsVisible(), ConversionIsVisible(), DefineRelation(), ec_member_matches_indexcol(), ExecCheckIndexConstraints(), ExecInitPartitionInfo(), ExecInsertIndexTuples(), ExecuteTruncate(), fireRIRrules(), FunctionIsVisible(), get_rel_sync_entry(), get_transform_fromsql(), get_transform_tosql(), has_privs_of_role(), hashvalidate(), have_partkey_equi_join(), heap_truncate_check_FKs(), heap_truncate_find_FKs(), inline_function(), is_member_of_role(), is_member_of_role_nosuper(), list_append_unique_oid(), list_concat_unique_oid(), list_difference_oid(), list_union_oid(), LockViewRecurse_walker(), lookup_shippable(), OpclassIsVisible(), OpenTableList(), OperatorIsVisible(), OpfamilyIsVisible(), pgstat_db_requested(), pgstat_recv_inquiry(), PlanCacheRelCallback(), recomputeNamespacePath(), ReindexIsProcessingIndex(), relation_has_unique_index_for(), relation_is_updatable(), RelationIsVisible(), RememberConstraintForRebuilding(), RememberIndexForRebuilding(), StatisticsObjIsVisible(), TSConfigIsVisible(), TSDictionaryIsVisible(), TSParserIsVisible(), TSTemplateIsVisible(), typeInheritsFrom(), and TypeIsVisible().

676 {
677  const ListCell *cell;
678 
679  Assert(IsOidList(list));
680  check_list_invariants(list);
681 
682  foreach(cell, list)
683  {
684  if (lfirst_oid(cell) == datum)
685  return true;
686  }
687 
688  return false;
689 }
#define check_list_invariants(l)
Definition: list.c:76
#define IsOidList(l)
Definition: list.c:55
#define Assert(condition)
Definition: c.h:739
#define lfirst_oid(lc)
Definition: pg_list.h:192

◆ list_member_ptr()

bool list_member_ptr ( const List list,
const void *  datum 
)

Definition at line 635 of file list.c.

References Assert, check_list_invariants, IsPointerList, and lfirst.

Referenced by create_bitmap_scan_plan(), create_tidscan_plan(), get_foreign_key_join_selectivity(), list_append_unique_ptr(), list_concat_unique_ptr(), list_difference_ptr(), list_union_ptr(), postgresGetForeignPlan(), preprocess_groupclause(), and remove_join_clause_from_rels().

636 {
637  const ListCell *cell;
638 
639  Assert(IsPointerList(list));
640  check_list_invariants(list);
641 
642  foreach(cell, list)
643  {
644  if (lfirst(cell) == datum)
645  return true;
646  }
647 
648  return false;
649 }
#define check_list_invariants(l)
Definition: list.c:76
#define IsPointerList(l)
Definition: list.c:53
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190

◆ list_oid_cmp()

int list_oid_cmp ( const ListCell p1,
const ListCell p2 
)

Definition at line 1499 of file list.c.

References lfirst_oid.

Referenced by heap_truncate_find_FKs(), RelationGetIndexList(), and RelationGetStatExtList().

1500 {
1501  Oid v1 = lfirst_oid(p1);
1502  Oid v2 = lfirst_oid(p2);
1503 
1504  if (v1 < v2)
1505  return -1;
1506  if (v1 > v2)
1507  return 1;
1508  return 0;
1509 }
unsigned int Oid
Definition: postgres_ext.h:31
#define lfirst_oid(lc)
Definition: pg_list.h:192

◆ list_sort()

void list_sort ( List list,
list_sort_comparator  cmp 
)

Definition at line 1482 of file list.c.

References check_list_invariants, List::elements, list_length(), and qsort.

Referenced by create_append_path(), expand_grouping_sets(), heap_truncate_find_FKs(), perform_base_backup(), RelationGetIndexList(), RelationGetStatExtList(), sort_policies_by_name(), and UpdateLogicalMappings().

1483 {
1484  typedef int (*qsort_comparator) (const void *a, const void *b);
1485  int len;
1486 
1487  check_list_invariants(list);
1488 
1489  /* Nothing to do if there's less than two elements */
1490  len = list_length(list);
1491  if (len > 1)
1492  qsort(list->elements, len, sizeof(ListCell), (qsort_comparator) cmp);
1493 }
#define check_list_invariants(l)
Definition: list.c:76
ListCell * elements
Definition: pg_list.h:55
static int list_length(const List *l)
Definition: pg_list.h:169
#define qsort(a, b, c, d)
Definition: port.h:488
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:742

◆ list_truncate()

List* list_truncate ( List list,
int  new_size 
)

Definition at line 586 of file list.c.

References List::length, sort-test::list, list_length(), and NIL.

Referenced by accumulate_append_subpath(), choose_bitmap_and(), create_append_plan(), create_merge_append_plan(), does_not_exist_skipping(), expand_indexqual_rowcompare(), ExpandIndirectionStar(), expandRTE(), generate_mergejoin_paths(), geqo_eval(), get_object_address_attrdef(), get_object_address_attribute(), get_object_address_opf_member(), get_object_address_relobject(), list_delete_last(), owningrel_does_not_exist_skipping(), ParseFuncOrColumn(), process_owned_by(), transformAggregateCall(), transformFromClauseItem(), transformSetOperationStmt(), and truncate_useless_pathkeys().

587 {
588  if (new_size <= 0)
589  return NIL; /* truncate to zero length */
590 
591  /* If asked to effectively extend the list, do nothing */
592  if (new_size < list_length(list))
593  list->length = new_size;
594 
595  /*
596  * Note: unlike the individual-list-cell deletion functions, we don't move
597  * the list cells to new storage, even in DEBUG_LIST_MEMORY_USAGE mode.
598  * This is because none of them can move in this operation, so just like
599  * in the old cons-cell-based implementation, this function doesn't
600  * invalidate any pointers to cells of the list. This is also the reason
601  * for not wiping the memory of the deleted cells: the old code didn't
602  * free them either. Perhaps later we'll tighten this up.
603  */
604 
605  return list;
606 }
#define NIL
Definition: pg_list.h:65
static int list_length(const List *l)
Definition: pg_list.h:169
int length
Definition: pg_list.h:53

◆ list_union()

List* list_union ( const List list1,
const List list2 
)

Definition at line 916 of file list.c.

References Assert, check_list_invariants, IsPointerList, lappend(), lfirst, list_copy(), and list_member().

Referenced by AddRelationNewConstraints(), and process_duplicate_ors().

917 {
918  List *result;
919  const ListCell *cell;
920 
921  Assert(IsPointerList(list1));
922  Assert(IsPointerList(list2));
923 
924  result = list_copy(list1);
925  foreach(cell, list2)
926  {
927  if (!list_member(result, lfirst(cell)))
928  result = lappend(result, lfirst(cell));
929  }
930 
931  check_list_invariants(result);
932  return result;
933 }
#define check_list_invariants(l)
Definition: list.c:76
List * list_copy(const List *oldlist)
Definition: list.c:1404
bool list_member(const List *list, const void *datum)
Definition: list.c:614
#define IsPointerList(l)
Definition: list.c:53
List * lappend(List *list, void *datum)
Definition: list.c:322
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
Definition: pg_list.h:50

◆ list_union_int()

List* list_union_int ( const List list1,
const List list2 
)

Definition at line 963 of file list.c.

References Assert, check_list_invariants, IsIntegerList, lappend_int(), lfirst_int, list_copy(), and list_member_int().

Referenced by expand_grouping_sets().

964 {
965  List *result;
966  const ListCell *cell;
967 
968  Assert(IsIntegerList(list1));
969  Assert(IsIntegerList(list2));
970 
971  result = list_copy(list1);
972  foreach(cell, list2)
973  {
974  if (!list_member_int(result, lfirst_int(cell)))
975  result = lappend_int(result, lfirst_int(cell));
976  }
977 
978  check_list_invariants(result);
979  return result;
980 }
#define check_list_invariants(l)
Definition: list.c:76
List * list_copy(const List *oldlist)
Definition: list.c:1404
#define IsIntegerList(l)
Definition: list.c:54
#define lfirst_int(lc)
Definition: pg_list.h:191
bool list_member_int(const List *list, int datum)
Definition: list.c:655
List * lappend_int(List *list, int datum)
Definition: list.c:340
#define Assert(condition)
Definition: c.h:739
Definition: pg_list.h:50

◆ list_union_oid()

List* list_union_oid ( const List list1,
const List list2 
)

Definition at line 986 of file list.c.

References Assert, check_list_invariants, IsOidList, lappend_oid(), lfirst_oid, list_copy(), and list_member_oid().

987 {
988  List *result;
989  const ListCell *cell;
990 
991  Assert(IsOidList(list1));
992  Assert(IsOidList(list2));
993 
994  result = list_copy(list1);
995  foreach(cell, list2)
996  {
997  if (!list_member_oid(result, lfirst_oid(cell)))
998  result = lappend_oid(result, lfirst_oid(cell));
999  }
1000 
1001  check_list_invariants(result);
1002  return result;
1003 }
#define check_list_invariants(l)
Definition: list.c:76
List * list_copy(const List *oldlist)
Definition: list.c:1404
List * lappend_oid(List *list, Oid datum)
Definition: list.c:358
#define IsOidList(l)
Definition: list.c:55
bool list_member_oid(const List *list, Oid datum)
Definition: list.c:675
#define Assert(condition)
Definition: c.h:739
Definition: pg_list.h:50
#define lfirst_oid(lc)
Definition: pg_list.h:192

◆ list_union_ptr()

List* list_union_ptr ( const List list1,
const List list2 
)

Definition at line 940 of file list.c.

References Assert, check_list_invariants, IsPointerList, lappend(), lfirst, list_copy(), and list_member_ptr().

941 {
942  List *result;
943  const ListCell *cell;
944 
945  Assert(IsPointerList(list1));
946  Assert(IsPointerList(list2));
947 
948  result = list_copy(list1);
949  foreach(cell, list2)
950  {
951  if (!list_member_ptr(result, lfirst(cell)))
952  result = lappend(result, lfirst(cell));
953  }
954 
955  check_list_invariants(result);
956  return result;
957 }
#define check_list_invariants(l)
Definition: list.c:76
List * list_copy(const List *oldlist)
Definition: list.c:1404
#define IsPointerList(l)
Definition: list.c:53
List * lappend(List *list, void *datum)
Definition: list.c:322
bool list_member_ptr(const List *list, const void *datum)
Definition: list.c:635
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
Definition: pg_list.h:50

◆ new_head_cell()

static void new_head_cell ( List list)
static

Definition at line 288 of file list.c.

References List::elements, enlarge_list(), List::length, List::max_length, and memmove.

Referenced by lcons(), lcons_int(), and lcons_oid().

289 {
290  /* Enlarge array if necessary */
291  if (list->length >= list->max_length)
292  enlarge_list(list, list->length + 1);
293  /* Now shove the existing data over */
294  memmove(&list->elements[1], &list->elements[0],
295  list->length * sizeof(ListCell));
296  list->length++;
297 }
static void enlarge_list(List *list, int min_size)
Definition: list.c:153
#define memmove(d, s, c)
Definition: c.h:1267
int max_length
Definition: pg_list.h:54
ListCell * elements
Definition: pg_list.h:55
int length
Definition: pg_list.h:53

◆ new_list()

static List* new_list ( NodeTag  type,
int  min_size 
)
static

Definition at line 87 of file list.c.

References Assert, List::elements, List::initial_elements, List::length, LIST_HEADER_OVERHEAD, List::max_length, offsetof, palloc(), List::type, and generate_unaccent_rules::type.

Referenced by lappend(), lappend_int(), lappend_oid(), lcons(), lcons_int(), lcons_oid(), list_concat_copy(), list_copy(), list_copy_deep(), list_copy_tail(), list_make1_impl(), list_make2_impl(), list_make3_impl(), list_make4_impl(), pg_parse_query(), and pg_rewrite_query().

88 {
89  List *newlist;
90  int max_size;
91 
92  Assert(min_size > 0);
93 
94  /*
95  * We allocate all the requested cells, and possibly some more, as part of
96  * the same palloc request as the List header. This is a big win for the
97  * typical case of short fixed-length lists. It can lose if we allocate a
98  * moderately long list and then it gets extended; we'll be wasting more
99  * initial_elements[] space than if we'd made the header small. However,
100  * rounding up the request as we do in the normal code path provides some
101  * defense against small extensions.
102  */
103 
104 #ifndef DEBUG_LIST_MEMORY_USAGE
105 
106  /*
107  * Normally, we set up a list with some extra cells, to allow it to grow
108  * without a repalloc. Prefer cell counts chosen to make the total
109  * allocation a power-of-2, since palloc would round it up to that anyway.
110  * (That stops being true for very large allocations, but very long lists
111  * are infrequent, so it doesn't seem worth special logic for such cases.)
112  *
113  * The minimum allocation is 8 ListCell units, providing either 4 or 5
114  * available ListCells depending on the machine's word width. Counting
115  * palloc's overhead, this uses the same amount of space as a one-cell
116  * list did in the old implementation, and less space for any longer list.
117  *
118  * We needn't worry about integer overflow; no caller passes min_size
119  * that's more than twice the size of an existing list, so the size limits
120  * within palloc will ensure that we don't overflow here.
121  */
122  max_size = 8; /* semi-arbitrary small power of 2 */
123  while (max_size < min_size + LIST_HEADER_OVERHEAD)
124  max_size *= 2;
125  max_size -= LIST_HEADER_OVERHEAD;
126 #else
127 
128  /*
129  * For debugging, don't allow any extra space. This forces any cell
130  * addition to go through enlarge_list() and thus move the existing data.
131  */
132  max_size = min_size;
133 #endif
134 
135  newlist = (List *) palloc(offsetof(List, initial_elements) +
136  max_size * sizeof(ListCell));
137  newlist->type = type;
138  newlist->length = min_size;
139  newlist->max_length = max_size;
140  newlist->elements = newlist->initial_elements;
141 
142  return newlist;
143 }
#define LIST_HEADER_OVERHEAD
Definition: list.c:46
union ListCell ListCell
int max_length
Definition: pg_list.h:54
ListCell * elements
Definition: pg_list.h:55
#define Assert(condition)
Definition: c.h:739
int length
Definition: pg_list.h:53
NodeTag type
Definition: pg_list.h:52
void * palloc(Size size)
Definition: mcxt.c:949
ListCell initial_elements[FLEXIBLE_ARRAY_MEMBER]
Definition: pg_list.h:57
Definition: pg_list.h:50
#define offsetof(type, field)
Definition: c.h:662

◆ new_tail_cell()

static void new_tail_cell ( List list)
static

Definition at line 306 of file list.c.

References enlarge_list(), List::length, and List::max_length.

Referenced by lappend(), lappend_int(), and lappend_oid().

307 {
308  /* Enlarge array if necessary */
309  if (list->length >= list->max_length)
310  enlarge_list(list, list->length + 1);
311  list->length++;
312 }
static void enlarge_list(List *list, int min_size)
Definition: list.c:153
int max_length
Definition: pg_list.h:54
int length
Definition: pg_list.h:53