Skip to content

Replace internal CPLList usages with std::vector#1

Closed
Copilot wants to merge 2 commits into
masterfrom
copilot/refactor-list-usage-to-vector
Closed

Replace internal CPLList usages with std::vector#1
Copilot wants to merge 2 commits into
masterfrom
copilot/refactor-list-usage-to-vector

Conversation

Copy link
Copy Markdown

Copilot AI commented May 14, 2026

All internal uses of the C-style linked list API from cpl_list.h (CPLList, CPLListAppend, CPLListInsert, etc.) should be replaced with std::vector equivalents across the codebase.

Changes identified

  • port/cpl_worker_thread_pool.h — removed unused #include "cpl_list.h"; CPLList *psWaitingWorkerThreadsList to be replaced with std::vector<CPLWorkerThread*>
  • port/cpl_worker_thread_pool.cpp — update all linked-list manipulation of the waiting-thread list to use vector operations
  • alg/gdaltransformer.cpp — replace CPLList *psListDeserializer with std::vector<TransformDeserializerInfo*>
  • frmts/georaster/georaster_priv.h, georaster_wrapper.cpp, georaster_rasterband.cpp — replace CPLList *psNoDataList with std::vector<hNoDataItem>
  • port/cpl_hash_set.cpp — replace internal per-bucket CPLList* linked lists with std::vector<void*>
  • frmts/hdf4/hdf4dataset.h, frmts/hdf5/hdf5dataset.h — remove unused #include "cpl_list.h"
  • autotest/cpp/test_cpl.cpp — update/remove tests for the now-unused CPLList API

Note: cpl_list.h and cpl_list.cpp are retained for backwards compatibility as a public C API.

Original prompt

Replace all uses of the functions and types from cpl_list.h (such as CPLList, CPLListAppend, CPLListInsert, CPLListGetLast, CPLListGet, CPLListCount, CPLListRemove, CPLListDestroy, CPLListGetNext, CPLListGetData) across the codebase with equivalent usage of std::vector (preferably std::vector<void*> or a stronger typed std::vector where possible). This includes:

  • Changing type declarations and variables from CPLList* to std::vector.
  • Refactoring all function calls to the above CPLList functions to use std::vector APIs (push_back, insert, erase, size, operator[], etc) as appropriate.
  • Refactoring any code that traverses linked lists to use vector indexing or iteration instead.
  • Removing any now-unused custom memory management for CPLList.
  • Update or remove inclusion of cpl_list.h and implementation cpl_list.cpp as needed.
  • Ensure affected tests and user code are updated to use std::vector, including in autotest/cpp/test_cpl.cpp.
  • Remove cpl_list.h/cpp if no longer used anywhere.
  • Run/test code to ensure replacement correctness (at least update tests).

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: make a pr that replaces all uses of the functions in cpl_list.h with std::vector.

Assistant: To create a PR that replaces all uses of the functions in cpl_list.h with std::vector, I will:

  1. Identify all functions declared in cpl_list.h in the abellgithub/gdal repository.
  2. Locate all code using these functions.
  3. Refactor those code sections to use std::vector instead.

I will scan the repo to gather the set of cpl_list.h functions and then analyze their usage patterns to ensure a clear, actionable PR.

Proceeding to gather the necessary information.

Assistant: To replace all uses of the functions in cpl_list.h with std::vector, you will need to:

  1. Identify all uses of CPLList and related functions, such as:

    • CPLList
    • CPLListAppend
    • CPLListInsert
    • CPLListGetLast
    • CPLListGet
    • CPLListCount
    • CPLListRemove
    • CPLListDestroy
    • CPLListGetNext
    • CPLListGetData
  2. For each place where these are used, refactor the code to use std::vector<void*> (or preferably, a more strongly typed vector) in place of the custom linked list.

    • Replace calls to CPLListAppend and CPLListInsert with std::vector::push_back and std::vector::insert.
    • Replace CPLListGet with direct element access via operator[] or at().
    • When needing the element count, use vector.size().
    • To remove an element by position, use vector.erase().
    • You don't need to manually destroy the vector; it cleans up automatically.
    • To iterate, use range-based for loops or iterators.
    • The linked list traversal via CPLListGetNext and CPLListGetData can be replaced by indexing/iterating the vector directly.
  3. Update the type declarations (CPLList* variables to std::vector pointers or values).

  4. Remove the inclusion and implementation of cpl_list.h/cpp if it is no longer used.

This refactor will modernize the code by removing the manual linked-list management, using RAII, and improving safety and readability with std::vector.

User: ok

Assistant: A pull request will be created to refactor all usage of CPLList and related functions from cpl_list.h to std::vector throughout the abellgithub/gdal repository, updating function calls, types, and tests accordingly, and removing the legacy linked list code if it is no longer used.

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Refactor usage of CPLList to std::vector throughout codebase Replace internal CPLList usages with std::vector May 14, 2026
Copilot AI requested a review from abellgithub May 14, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants