From 37f182f4e4d790b72ef2b45ea65569374a33e74c Mon Sep 17 00:00:00 2001 From: lif0 <22912194+lif0@users.noreply.github.com> Date: Wed, 17 Jun 2026 15:43:45 +0300 Subject: [PATCH 1/2] feat: make big refactor miguel; --- .github/ISSUE_TEMPLATE/bug.md | 2 +- .github/ISSUE_TEMPLATE/feature.md | 2 +- .../assets/badges/coverage-concurrency.json | 1 - .github/assets/badges/coverage-sync.json | 1 - .github/assets/badges/coverage-utils.json | 1 - .github/scripts/pre-push | 76 -- .github/workflows/build.yml | 17 +- .github/workflows/coverallsapp.yml | 55 +- .github/workflows/create_release.yml | 228 +--- .github/workflows/tests.yml | 17 +- .../workflows/update_coverage-submodules.yml | 58 - CHANGELOG.md | 52 + CONTRIBUTING.md | 18 +- Makefile | 9 +- README.md | 148 ++- SECURITY.md | 4 +- TODO.md | 3 +- async/doc.go | 3 + {concurrency => async}/future_action.go | 2 +- {concurrency => async}/future_action_test.go | 6 +- {concurrency => async}/promise_with_future.go | 2 +- .../promise_with_future_test.go | 20 +- {concurrency/chanx => chanx}/empty.go | 0 {concurrency/chanx => chanx}/fan_in.go | 0 {concurrency/chanx => chanx}/fan_in_test.go | 2 +- {concurrency/chanx => chanx}/helpers.go | 0 {concurrency/chanx => chanx}/helpers_test.go | 2 +- concurrency/CHANGELOG.md | 31 - concurrency/README.md | 652 ----------- concurrency/empty.go | 2 - concurrency/go.mod | 11 - concurrency/go.sum | 10 - {utils/errx => errx}/multi_error.go | 0 {utils/errx => errx}/multi_error_test.go | 2 +- sync/go.mod => go.mod | 4 +- sync/go.sum => go.sum | 0 {utils/internal => internal}/chain.go | 0 {utils/internal => internal}/chain_test.go | 2 +- reflectx/doc.go | 3 + .../reflect => reflectx}/estimate_payload.go | 2 +- .../estimate_payload_bench_out.txt | 0 .../estimate_payload_bench_test.go | 76 +- .../estimate_payload_test.go | 1038 ++++++++--------- {utils/structx => structx}/object_pool.go | 0 .../structx => structx}/object_pool_test.go | 2 +- {utils/structx => structx}/ordered_map.go | 2 +- .../ordered_map_bench_test.go | 2 +- .../structx => structx}/ordered_map_test.go | 2 +- sync/CHANGELOG.md | 14 - sync/README.md | 191 --- sync/empty.go | 2 - {concurrency => syncx}/lock.go | 2 +- {concurrency => syncx}/lock_test.go | 12 +- {sync => syncx}/noCopy.go | 2 +- {sync => syncx}/noCopy_internal_test.go | 2 +- {sync => syncx}/reentrant_mutex.go | 4 +- {sync => syncx}/reentrant_mutex_bench.txt | 0 {sync => syncx}/reentrant_mutex_bench_test.go | 2 +- {sync => syncx}/reentrant_mutex_test.go | 2 +- {concurrency => syncx}/semaphore_chan.go | 4 +- {concurrency => syncx}/semaphore_chan_test.go | 24 +- {concurrency => syncx}/sync_value.go | 2 +- .../sync_value_banch_test.go | 14 +- {concurrency => syncx}/sync_value_test.go | 28 +- utils/CHANGELOG.md | 20 - utils/README.md | 329 ------ utils/empty.go | 2 - utils/go.mod | 11 - utils/go.sum | 10 - 69 files changed, 811 insertions(+), 2436 deletions(-) delete mode 100644 .github/assets/badges/coverage-concurrency.json delete mode 100644 .github/assets/badges/coverage-sync.json delete mode 100644 .github/assets/badges/coverage-utils.json delete mode 100755 .github/scripts/pre-push delete mode 100644 .github/workflows/update_coverage-submodules.yml create mode 100644 CHANGELOG.md create mode 100644 async/doc.go rename {concurrency => async}/future_action.go (98%) rename {concurrency => async}/future_action_test.go (72%) rename {concurrency => async}/promise_with_future.go (99%) rename {concurrency => async}/promise_with_future_test.go (86%) rename {concurrency/chanx => chanx}/empty.go (100%) rename {concurrency/chanx => chanx}/fan_in.go (100%) rename {concurrency/chanx => chanx}/fan_in_test.go (99%) rename {concurrency/chanx => chanx}/helpers.go (100%) rename {concurrency/chanx => chanx}/helpers_test.go (98%) delete mode 100644 concurrency/CHANGELOG.md delete mode 100644 concurrency/README.md delete mode 100644 concurrency/empty.go delete mode 100644 concurrency/go.mod delete mode 100644 concurrency/go.sum rename {utils/errx => errx}/multi_error.go (100%) rename {utils/errx => errx}/multi_error_test.go (98%) rename sync/go.mod => go.mod (86%) rename sync/go.sum => go.sum (100%) rename {utils/internal => internal}/chain.go (100%) rename {utils/internal => internal}/chain_test.go (99%) create mode 100644 reflectx/doc.go rename {utils/reflect => reflectx}/estimate_payload.go (99%) rename {utils/reflect => reflectx}/estimate_payload_bench_out.txt (100%) rename {utils/reflect => reflectx}/estimate_payload_bench_test.go (76%) rename {utils/reflect => reflectx}/estimate_payload_test.go (80%) rename {utils/structx => structx}/object_pool.go (100%) rename {utils/structx => structx}/object_pool_test.go (95%) rename {utils/structx => structx}/ordered_map.go (98%) rename {utils/structx => structx}/ordered_map_bench_test.go (99%) rename {utils/structx => structx}/ordered_map_test.go (99%) delete mode 100644 sync/CHANGELOG.md delete mode 100644 sync/README.md delete mode 100644 sync/empty.go rename {concurrency => syncx}/lock.go (96%) rename {concurrency => syncx}/lock_test.go (82%) rename {sync => syncx}/noCopy.go (96%) rename {sync => syncx}/noCopy_internal_test.go (94%) rename {sync => syncx}/reentrant_mutex.go (97%) rename {sync => syncx}/reentrant_mutex_bench.txt (100%) rename {sync => syncx}/reentrant_mutex_bench_test.go (99%) rename {sync => syncx}/reentrant_mutex_test.go (99%) rename {concurrency => syncx}/semaphore_chan.go (96%) rename {concurrency => syncx}/semaphore_chan_test.go (90%) rename {concurrency => syncx}/sync_value.go (99%) rename {concurrency => syncx}/sync_value_banch_test.go (90%) rename {concurrency => syncx}/sync_value_test.go (91%) delete mode 100644 utils/CHANGELOG.md delete mode 100644 utils/README.md delete mode 100644 utils/empty.go delete mode 100644 utils/go.mod delete mode 100644 utils/go.sum diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md index ba5ca3a..8b11349 100644 --- a/.github/ISSUE_TEMPLATE/bug.md +++ b/.github/ISSUE_TEMPLATE/bug.md @@ -38,4 +38,4 @@ Add any other context about the problem here. --> ### Sub-Module Label (Required) -Please select and apply the appropriate label for the affected sub-module (e.g., `pkg/sync`, `pkg/concurrency`, `pkg/utils`). This helps route the issue to the right team. If unsure, describe the sub-module in the additional context section. \ No newline at end of file +Please select and apply the appropriate label for the affected sub-module (e.g., `async`, `syncx`, `chanx`, `errx`, `structx`, `reflectx`). This helps route the issue to the right team. If unsure, describe the sub-module in the additional context section. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature.md b/.github/ISSUE_TEMPLATE/feature.md index 22af938..d2cecad 100644 --- a/.github/ISSUE_TEMPLATE/feature.md +++ b/.github/ISSUE_TEMPLATE/feature.md @@ -19,4 +19,4 @@ Clarify how we can verify that the task is done. --> # Sub-Module Label (Required) -Please select and apply the appropriate label for the affected sub-module (e.g., `pkg/sync`, `pkg/concurrency`, `pkg/utils`). This helps route the issue to the right team. If unsure, describe the sub-module in the additional context section. \ No newline at end of file +Please select and apply the appropriate label for the affected sub-module (e.g., `async`, `syncx`, `chanx`, `errx`, `structx`, `reflectx`). This helps route the issue to the right team. If unsure, describe the sub-module in the additional context section. \ No newline at end of file diff --git a/.github/assets/badges/coverage-concurrency.json b/.github/assets/badges/coverage-concurrency.json deleted file mode 100644 index 40465d8..0000000 --- a/.github/assets/badges/coverage-concurrency.json +++ /dev/null @@ -1 +0,0 @@ -{"schemaVersion":1,"label":"coverage","message":"100.0%","color":"#37c955","style":"flat"} diff --git a/.github/assets/badges/coverage-sync.json b/.github/assets/badges/coverage-sync.json deleted file mode 100644 index 40465d8..0000000 --- a/.github/assets/badges/coverage-sync.json +++ /dev/null @@ -1 +0,0 @@ -{"schemaVersion":1,"label":"coverage","message":"100.0%","color":"#37c955","style":"flat"} diff --git a/.github/assets/badges/coverage-utils.json b/.github/assets/badges/coverage-utils.json deleted file mode 100644 index cc963da..0000000 --- a/.github/assets/badges/coverage-utils.json +++ /dev/null @@ -1 +0,0 @@ -{"schemaVersion":1,"label":"coverage","message":"99.2%","color":"#37c955","style":"flat"} diff --git a/.github/scripts/pre-push b/.github/scripts/pre-push deleted file mode 100755 index a468fe1..0000000 --- a/.github/scripts/pre-push +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/bash -set -euo pipefail - -echo "Запуск pre-push хука..." - -# Проверка наличия Go -if ! command -v go >/dev/null 2>&1; then - echo "Ошибка: Go не найден. Убедитесь, что Go установлен." - exit 1 -fi - -which go -go version - -# Создание директории для бейджей -mkdir -p ../../.github/assets/badges - -echo "`pwd`" - -# Поиск всех go.mod файлов в папках и подпапках -find . -type f -name "go.mod" | while read -r mod_file; do - # Извлечение директории модуля - module_dir=$(dirname "$mod_file") - # Имя модуля (название папки) - module=$(basename "$module_dir") - - echo "Обработка модуля $module в директории $module_dir" - - # Переход в директорию модуля - pushd "$module_dir" > /dev/null - - # Имя файла покрытия - FILE="coverage_package_${module}.out" - - # Генерация файла покрытия - echo "Генерация покрытия для $module..." - go test ./... -race -covermode=atomic -coverprofile="$FILE" - if [ $? -ne 0 ]; then - echo "Ошибка: не удалось сгенерировать покрытие для $module" - popd > /dev/null - exit 1 - fi - - # Извлечение процента покрытия - COV=$(go tool cover -func="$FILE" | grep total | awk '{print $3}') - if [ -z "$COV" ]; then - echo "Ошибка: не удалось извлечь покрытие для $module" - popd > /dev/null - exit 1 - fi - - NUM=${COV%\%} - if (( $(echo "$NUM >= 95" | bc -l) )); then - COLOR="#37c955" - elif (( $(echo "$NUM >= 85" | bc -l) )); then - COLOR="yellow" - else - COLOR="red" - fi - - echo "`pwd`..." - - cd .. - - # Создание JSON-бейджа - echo "{\"schemaVersion\":1,\"label\":\"coverage\",\"message\":\"$COV\",\"color\":\"$COLOR\",\"style\":\"flat\"}" > ".github/assets/badges/coverage-${module}.json" - - # Добавление JSON-бейджа в индекс Git - #git add ".github/assets/badges/${module}.json" - - # Возврат в исходную директорию - popd > /dev/null -done - -echo "Pre-push хук успешно завершен." -exit 0 \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7ec9eef..2b99fac 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,18 +3,10 @@ on: push: pull_request: -env: - GO_VERSION: stable - jobs: - build: name: Build Project runs-on: ubuntu-latest - strategy: - matrix: - module: [utils, concurrency, sync] - steps: - name: Checkout code uses: actions/checkout@v4 @@ -22,14 +14,9 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: ${{ env.GO_VERSION }} + go-version-file: go.mod cache: true - cache-dependency-path: ${{ matrix.module }}/go.sum check-latest: false - name: go build - working-directory: ${{ matrix.module }} - run: | - go build ./... - env: - GOPATH: /home/runner/work/${{ github.event.repository.name }}/go \ No newline at end of file + run: go build ./... diff --git a/.github/workflows/coverallsapp.yml b/.github/workflows/coverallsapp.yml index afffd5f..3a738e6 100644 --- a/.github/workflows/coverallsapp.yml +++ b/.github/workflows/coverallsapp.yml @@ -1,40 +1,18 @@ name: test coverage coverallsapp on: - workflow_run: - workflows: ["build"] - types: - - completed push: branches: - main - paths: - - '**.go' - - 'utils/**' - - 'concurrency/**' - - 'sync/**' - - '.github/workflows/**' pull_request: branches: - '**' permissions: contents: read # чтоб бейджи грузились -# pull-requests: write - -env: - GO_VERSION: stable jobs: - test: + coverage: runs-on: ubuntu-latest - strategy: - fail-fast: true - matrix: - module: [utils, concurrency, sync] - defaults: - run: - working-directory: ${{ matrix.module }} - steps: - name: Clone repo uses: actions/checkout@v4 @@ -42,11 +20,8 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version-file: ${{ matrix.module }}/go.mod + go-version-file: go.mod cache: true - cache-dependency-path: ${{ matrix.module }}/go.sum - #go-version: ${{ env.GO_VERSION }} - #cache-dependency-path: ${{ matrix.module }}/go.sum - name: Vet run: go vet ./... @@ -55,29 +30,11 @@ jobs: run: go build ./... - name: Test - run: | - go test ./... -race -covermode=atomic -coverprofile=coverage_package_${{ matrix.module }}.out - pwd - ls + run: go test ./... -race -covermode=atomic -coverprofile=coverage.out - - name: Upload to Coveralls (flag = module) + - name: Upload to Coveralls uses: coverallsapp/github-action@v2 with: github-token: ${{ secrets.GITHUB_TOKEN }} - file: ${{ matrix.module }}/coverage_package_${{ matrix.module }}.out - format: golang - flag-name: ${{ matrix.module }} - parallel: true - - finish: - needs: test - if: always() - runs-on: ubuntu-latest - steps: - - name: Finish upload to Coveralls - uses: coverallsapp/github-action@v2 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - #coveralls-token: ${{ secrets.COVERALLS_TOKEN }} - parallel-finished: true - carryforward: "utils,concurrency,sync" \ No newline at end of file + file: coverage.out + format: golang diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index 598fa75..20b9650 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -1,26 +1,18 @@ -name: 🧰 Go Module Release UI +name: 🧰 Release on: workflow_dispatch: inputs: - go_module: - description: "Choice submodule" - type: choice - options: - - concurrency - - utils - - sync - default: concurrency version: description: "Version (example: v1.0.1 or 1.0.1 — prefix `v` will be added)" required: true make_latest: description: "Mark as latest" type: choice - options: ["false", "true", "legacy"] + options: ["true", "false", "legacy"] default: "true" prerelease: - description: "Пререлиз? (оставьте пустым для автоопределения по суффиксу версии)" + description: "Prerelease? (leave empty to auto-detect by version suffix)" required: false permissions: @@ -30,228 +22,42 @@ jobs: release: runs-on: ubuntu-latest steps: - - name: Checkout selected branch + - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 ref: ${{ github.ref }} - - name: Resolve module paths and compute tag/name + - name: Compute tag and prerelease flag id: vars shell: bash run: | set -euo pipefail - GO_MODULE="${{ inputs.go_module }}" - VERSION_IN="${{ inputs.version }}" - MAKE_LATEST="${{ inputs.make_latest }}" - INPUT_PRERELEASE="${{ inputs.prerelease || '' }}" - REPO="${GITHUB_REPOSITORY}" # owner/repo - - GO_MOD="${GO_MODULE}/go.mod" - if [[ ! -f "$GO_MOD" ]]; then - echo "::error::Файл '$GO_MOD' не найден. Ожидаю структуру '/go.mod'." - exit 1 - fi - - # module path from go.mod - MODULE_PATH="$(awk '/^module[[:space:]]+/ {print $2; exit}' "$GO_MOD")" - if [[ -z "$MODULE_PATH" ]]; then - echo "::error::Не удалось извлечь module path из '$GO_MOD'." - exit 1 - fi - - # derive module_dir for Go tag (github.com///) - MODULE_DIR="$GO_MODULE" - prefix="github.com/${REPO}/" - if [[ "$MODULE_PATH" == ${prefix}* ]]; then - MODULE_DIR="${MODULE_PATH#${prefix}}" - fi - - MODULE_NAME="$(basename "$MODULE_PATH")" - DIR_REL="$GO_MODULE" - - # normalize version: add leading 'v' if missing - VERSION="$VERSION_IN" + VERSION="${{ inputs.version }}" [[ "$VERSION" =~ ^v ]] || VERSION="v${VERSION}" - # prerelease auto-detect PRERELEASE="false" - if [[ -n "$INPUT_PRERELEASE" ]]; then + INPUT_PRE="${{ inputs.prerelease || '' }}" + if [[ -n "$INPUT_PRE" ]]; then shopt -s nocasematch - if [[ "$INPUT_PRERELEASE" =~ ^(1|true|yes|y)$ ]]; then PRERELEASE="true"; fi - if [[ "$INPUT_PRERELEASE" =~ ^(0|false|no|n)$ ]]; then PRERELEASE="false"; fi + [[ "$INPUT_PRE" =~ ^(1|true|yes|y)$ ]] && PRERELEASE="true" shopt -u nocasematch - else - if [[ "$VERSION" == *"-"* ]]; then PRERELEASE="true"; fi + elif [[ "$VERSION" == *"-"* ]]; then + PRERELEASE="true" fi - # compute tag as / - TAG="${MODULE_DIR}/${VERSION}" - TAG="${TAG#/}" ; TAG="${TAG%/}" - - NAME="${MODULE_NAME} ${VERSION}" - - echo "module_path=$MODULE_PATH" >> "$GITHUB_OUTPUT" - echo "module_name=$MODULE_NAME" >> "$GITHUB_OUTPUT" - echo "dir_rel=$DIR_REL" >> "$GITHUB_OUTPUT" - echo "module_dir=$MODULE_DIR" >> "$GITHUB_OUTPUT" echo "version=$VERSION" >> "$GITHUB_OUTPUT" - echo "tag=$TAG" >> "$GITHUB_OUTPUT" - echo "name=$NAME" >> "$GITHUB_OUTPUT" - echo "make_latest=$MAKE_LATEST" >> "$GITHUB_OUTPUT" echo "prerelease=$PRERELEASE" >> "$GITHUB_OUTPUT" - - name: Get current HEAD SHA - id: head - shell: bash - run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" - - - name: Find previous tag for this module - id: prev - shell: bash - run: | - set -euo pipefail - moduleDir="${{ steps.vars.outputs.module_dir }}" - pattern="${moduleDir}/v*" - prev_tag="$(git tag --list "$pattern" --sort=-v:refname | head -n1 || true)" - echo "prev_tag=$prev_tag" >> "$GITHUB_OUTPUT" - if [[ -n "$prev_tag" ]]; then - echo "Previous tag: $prev_tag" - else - echo "No previous tag found for pattern '$pattern'." - fi - - - name: Generate module-specific CHANGELOG (scoped only) - id: changelog - shell: bash - run: | - #set -x # Включить отладку - set -euo pipefail - - modulePath="${{ steps.vars.outputs.dir_rel }}" - moduleName="${{ steps.vars.outputs.module_name }}" - prev="${{ steps.prev.outputs.prev_tag }}" - file="CHANGELOG-${moduleName}.md" - - # Build git range - range="" - if [[ -n "$prev" ]]; then - range="$prev..HEAD" - baseLabel="$prev" - else - baseLabel="" - fi - - # Prepare lc variants once - module_name_lc="${moduleName,,}" - module_base_lc="$(basename -- "$modulePath")" - module_base_lc="${module_base_lc,,}" - - # Include commits with Conventional Commit scope matching the module - mapfile -t all_in_range < <(git log --no-merges --pretty=format:%H ${range} || true) - commits=() - for sha in "${all_in_range[@]}"; do - subj="$(git show -s --format='%s' "$sha")" - # Обновляем регулярное выражение для обработки префиксов [PKG-0] - if [[ "$subj" =~ ^(\[[^]]+\][[:space:]]*)?[a-zA-Z]+\(([^\)]+)\) ]]; then - scope="${BASH_REMATCH[2]}" # Теперь вторая группа захвата - IFS=',' read -ra scopes <<< "$scope" - for s in "${scopes[@]}"; do - s_trim="$(echo "$s" | xargs)" - s_trim_lc="${s_trim,,}" - if [[ "$s_trim_lc" == "$module_name_lc" || "$s_trim_lc" == "$module_base_lc" || "$s_trim_lc" == "$module_name_lc/"* ]]; then - commits+=("$sha") - break - fi - done - fi - done - - echo >> "$file" - if [[ -n "$baseLabel" ]]; then - echo "_Сравнение с **$baseLabel**_" >> "$file" - echo >> "$file" - fi - - # Group by Conventional Commit type - types=("feat" "fix" "perf" "refactor" "docs" "test" "build" "ci" "chore" "deps" "other") - declare -A groups - for t in "${types[@]}"; do groups["$t"]=""; done - - for sha in "${commits[@]}"; do - subj="$(git show -s --format='%s' "$sha")" - short="$(git show -s --format='%h' "$sha")" - author="$(git show -s --format='%an' "$sha")" - - type="other" - # Используем grep для определения типа - if echo "$subj" | grep -E -q "^[[:space:]]*(\[.*\][[:space:]]*)?(feat|fix|perf|refactor|test|build|ci|chore|deps)(\([^)]*\))?[[:space:]]*:"; then - t=$(echo "$subj" | sed -E 's/^[[:space:]]*(\[.*\][[:space:]]*)?([a-zA-Z]+).*/\2/' | tr '[:upper:]' '[:lower:]') - case "$t" in - feat|fix|perf|refactor|docs|test|build|ci|chore|deps) type="$t" ;; - *) type="other" ;; - esac - else - echo "⚠️ Skip non-conventional commit: $subj" - continue - fi - - # Extract PR number pattern " (#123)" or "PR #123" - pr="" - if [[ "$subj" =~ \(#([0-9]+)\) ]]; then pr="#${BASH_REMATCH[1]}"; fi - if [[ -z "$pr" && "$subj" =~ [Pp][Rr][[:space:]]*#([0-9]+) ]]; then pr="#${BASH_REMATCH[1]}"; fi - - entry="- ${subj} (${short}) by @${author}" - [[ -n "$pr" ]] && entry="${entry} ${pr}" - groups["$type"]+="${entry}\\n" - done - - # Emit groups - for t in "${types[@]}"; do - content="${groups[$t]}" - if [[ -n "$content" ]]; then - case "$t" in - feat) h="✨ Features" ;; - fix) h="🐛 Fixes" ;; - perf) h="⚡️ Performance" ;; - refactor) h="🧹 Refactoring" ;; - docs) h="📝 Docs" ;; - #test) h="✅ Tests" ;; - #build) h="🏗️ Build" ;; - #ci) h="🔁 CI" ;; - chore) h="🧺 Chore" ;; - deps) h="📦 Dependencies" ;; - other) h="🍊 Other" ;; - esac - echo "## ${h}" >> "$file" - printf "%b" "$content" >> "$file" - echo >> "$file" - fi - done - - if ! grep -q "## " "$file"; then - echo "- No changes detected for this module in the selected range." >> "$file" - fi - - - echo "## 📦 How install" >> "$file" - echo '```' >> "$file" - echo "go get github.com/lif0/pkg/${moduleName}@${{ steps.vars.outputs.version }}" >> "$file" - echo '```' >> "$file" - - echo "file=$file" >> "$GITHUB_OUTPUT" - echo "Generated $file" - - name: Create GitHub Release uses: softprops/action-gh-release@v2 with: - tag_name: ${{ steps.vars.outputs.tag }} - name: ${{ steps.vars.outputs.name }} - target_commitish: ${{ steps.head.outputs.sha }} - body_path: ${{ steps.changelog.outputs.file }} - generate_release_notes: false - make_latest: ${{ steps.vars.outputs.make_latest }} + tag_name: ${{ steps.vars.outputs.version }} + name: ${{ steps.vars.outputs.version }} + target_commitish: ${{ github.sha }} + generate_release_notes: true + make_latest: ${{ inputs.make_latest }} draft: false prerelease: ${{ steps.vars.outputs.prerelease }} env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 22cf229..8f3af6e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,17 +1,9 @@ name: Multi-version Tests on: - workflow_run: - workflows: ["build"] - types: - - completed push: branches: - main - paths: - - 'utils/**' - - 'concurrency/**' - - 'sync/**' pull_request: branches: - '**' @@ -25,11 +17,7 @@ jobs: strategy: fail-fast: false # Allow all versions to run even if one fails matrix: - module: [utils, concurrency, sync] - go-version: ['1.22', '1.23', '1.24'] - defaults: - run: - working-directory: ${{ matrix.module }} + go-version: ['1.23', '1.24', 'stable'] steps: - name: Clone repo @@ -40,7 +28,6 @@ jobs: with: go-version: ${{ matrix.go-version }} cache: true - cache-dependency-path: ${{ matrix.module }}/go.sum - name: Vet run: go vet ./... @@ -49,4 +36,4 @@ jobs: run: go build ./... - name: Test - run: go test ./... -race \ No newline at end of file + run: go test ./... -race diff --git a/.github/workflows/update_coverage-submodules.yml b/.github/workflows/update_coverage-submodules.yml deleted file mode 100644 index f95f873..0000000 --- a/.github/workflows/update_coverage-submodules.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: update coverage submodules - -on: - workflow_run: - workflows: ["test coverage coverallsapp"] - types: - - completed - push: - branches: - - main - # Если пуш состоит ТОЛЬКО из изменений в папке с бейджами, - # workflow не запустится — это главный анти-цикл. - paths-ignore: - - '.github/assets/badges/**' - -permissions: - contents: write - -concurrency: - group: badges-${{ github.ref }} - cancel-in-progress: false - -jobs: - build-badges: - # Если вдруг всё-таки триггернется от коммита бота — пропускаем. - if: github.actor != 'github-actions[bot]' - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 # понадобится для пуша обратно - - - name: Make script executable - run: chmod +x .github/scripts/pre-push - - - name: Run badge generator - shell: bash - run: ./.github/scripts/pre-push - - - name: Commit & push badges if changed - shell: bash - run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - - # Добавляем только директорию с бейджами - git add .github/assets/badges || true - - # Коммитим только если есть изменения - if git diff --cached --quiet; then - echo "No badge changes. Skipping commit." - else - git commit -m "[skip-ci]tests(coverage.json): recalculate submodules coverage" - # Пушим обратно в ту же ветку - git push origin HEAD:${GITHUB_REF#refs/heads/} - fi \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..150010e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,52 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] YYYY-MM-DD +### Added +### Fixed +### Changed + +## [v1.0.0] - 2026-06-17 +The repository is now a **single Go module** (`github.com/lif0/pkg`) instead of three +separate modules (`concurrency`, `sync`, `utils`). Packages were reorganized, the former +`concurrency` module was split into `async` (futures/promises) and `syncx` (locks), and a +couple of packages were renamed to stop shadowing the standard library. + +### Changed (BREAKING — import paths changed) + +| Old import | New import | +| --- | --- | +| `github.com/lif0/pkg/concurrency` — `Promise`, `Future`, `FutureAction` | `github.com/lif0/pkg/async` | +| `github.com/lif0/pkg/concurrency` — `Semaphore`, `SyncValue`, `WithLock` | `github.com/lif0/pkg/syncx` | +| `github.com/lif0/pkg/concurrency/chanx` | `github.com/lif0/pkg/chanx` | +| `github.com/lif0/pkg/sync` — `ReentrantMutex` | `github.com/lif0/pkg/syncx` | +| `github.com/lif0/pkg/utils/errx` | `github.com/lif0/pkg/errx` | +| `github.com/lif0/pkg/utils/structx` | `github.com/lif0/pkg/structx` | +| `github.com/lif0/pkg/utils/reflect` | `github.com/lif0/pkg/reflectx` | + +- Minimum Go version is now **1.23** for the whole module. +- CI simplified to a single module: removed the per-module build/test matrix, the + parallel Coveralls aggregation, and the badge-generating bot. + +> Older tags (`concurrency/v*`, `sync/v*`, `utils/v*`) remain available, so existing pins +> keep building. New releases are published as plain `vX.Y.Z` on `github.com/lif0/pkg`. + +--- + +## Legacy history (pre-unification) + +### concurrency +- **v1.2.0** (2025-10-29) — [PKG-20](https://github.com/lif0/pkg/issues/28) Add `SyncValue[T]` +- **v1.1.0** — [PKG-1](https://github.com/lif0/pkg/issues/1) Add `chanx.FanIn` pattern +- **v1.0.1** — [PKG-11](https://github.com/lif0/pkg/issues/11) Introduce `FutureAction` pattern +- **v1.0.0** — [PKG-3](https://github.com/lif0/pkg/issues/3) Add `WithLock`; [PKG-4](https://github.com/lif0/pkg/issues/4) Add `Semaphore` + +### sync +- **v1.2.0** (2025-10-29) — Set minimum go version as 1.19 + +### utils +- **v1.2.0** (2025-10-29) — [PKG-18](https://github.com/lif0/pkg/issues/18) Set minimum go version as 1.23; Add `OrderedMap[K]V`; [PKG-28](https://github.com/lif0/pkg/issues/28) Add `ObjectPool[T]` +- **v1.0.1** — [PKG-16] Add `errx.MultiError` diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8a3c00e..7f5c9fd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,15 +17,15 @@ We encourage pull requests for bug fixes, features, documentation improvements, 1. **Fork the Repository**: Create your own fork of the repo. 2. **Create a Branch**: Branch names must follow the format `//`, where: - - `` is the affected package (e.g., `utils`, `concurrency`, `sync`). + - `` is the affected package (e.g., `async`, `syncx`, `chanx`, `errx`, `structx`, `reflectx`). - `` is the change type (e.g., `feature`, `fix`, `docs`, `test`). - `` is a short, descriptive name (use hyphens for spaces). Examples: - - `utils/feature/add-new-string-util` - - `concurrency/fix/deadlock-in-semaphore` - - `sync/docs/update-mutex-usage` - - `utils/feature/PKG-123` + - `structx/feature/add-new-string-util` + - `syncx/fix/deadlock-in-semaphore` + - `syncx/docs/update-mutex-usage` + - `async/feature/PKG-123` 3. **Make Changes**: - Ensure your code aligns with the project's goals: low-level, high-performance, minimal dependencies (prefer standard library). @@ -36,11 +36,11 @@ We encourage pull requests for bug fixes, features, documentation improvements, - Update documentation (e.g., godoc comments) and README if needed. 4. **Commit Your Changes**: Use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) for commit messages. Examples: - - `feat(concurrency): add new semaphore implementation` - - `[PKG-XX]feat(concurrency): add new semaphore implementation` - - `fix(utils): resolve panic in edge case` + - `feat(syncx): add new semaphore implementation` + - `[PKG-XX]feat(syncx): add new semaphore implementation` + - `fix(structx): resolve panic in edge case` - `docs: update README with new package details` - - `test(sync): add benchmarks for mutex` + - `test(syncx): add benchmarks for mutex` 5. **Test Thoroughly**: - Run `go test ./...` to ensure all tests pass. diff --git a/Makefile b/Makefile index 7bad580..5be0770 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,9 @@ tidy: - find . -name 'go.mod' -print -execdir sh -c 'echo "→ $$PWD"; go mod tidy' \; \ No newline at end of file + go mod tidy + +test: + go test ./... -race + +cover: + go test ./... -race -covermode=atomic -coverprofile=coverage.out + go tool cover -func=coverage.out diff --git a/README.md b/README.md index ce714bd..188cafd 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,22 @@ + + +Go Reference + + + +Coverage Status + + + + + + + + + @@ -19,89 +35,69 @@ package doc about - badges - - - - - - - - - - - - - - - -

Concurrency utilities for Go

- - - - - - - concurrency coverage - - - - - - - - - - - - - - - - -

Utils for Go

- - - - - - - utils coverage - - - - - - - - - - - - - - - - -

Extends the sync package.

- - - - - - - sync coverage - - - - + + + + async + go.dev + Futures, promises, and deferred actions + + + syncx + go.dev + Synchronization primitives: reentrant mutex, semaphore, sync value, WithLock + + + chanx + go.dev + Channel helpers: fan-in, send/receive conversions + + + errx + go.dev + Error utilities: MultiError + + + structx + go.dev + Data structures: OrderedMap, ObjectPool + + + reflectx + go.dev + Reflection helpers: payload-size estimation + + --- +## Install + +```bash +go get github.com/lif0/pkg@latest +``` + +```go +import ( + "github.com/lif0/pkg/async" + "github.com/lif0/pkg/syncx" + "github.com/lif0/pkg/chanx" + "github.com/lif0/pkg/errx" + "github.com/lif0/pkg/structx" + "github.com/lif0/pkg/reflectx" +) +``` + +> **Migrating from the old multi-module layout?** See [CHANGELOG.md](./CHANGELOG.md) for the +> import-path mapping. Old tags (`concurrency/v*`, `sync/v*`, `utils/v*`) still resolve, so +> existing pins keep working. + +--- + ## Purpose This repository provides a set of **low-level**, production-grade packages for Go — designed for **maximum performance**, **zero allocations where possible**, and **clean, idiomatic APIs**. diff --git a/SECURITY.md b/SECURITY.md index 212854a..d998968 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -4,9 +4,7 @@ | Version | Supported | | ------- | ------------------ | -| pkg/sync@v1.x.x | :white_check_mark: | -| pkg/concurrency@v1.x.x | :white_check_mark: | -| pkg/utils@v1.x.x | :white_check_mark: | +| github.com/lif0/pkg@v1.x.x | :white_check_mark: | ## Reporting a Vulnerability diff --git a/TODO.md b/TODO.md index 853613b..38738fc 100644 --- a/TODO.md +++ b/TODO.md @@ -3,10 +3,11 @@ # utils ## EstimatePayloadOf + - [ ] Попробовать превысчитать размеры для кейсов где используется unsafe и сравнить разницу ```bash go test -bench=ArrayValue -benchmem > old.txt go test -bench=ArrayPointer -benchmem > new.txt benchstat old.txt new.txt -``` \ No newline at end of file +``` diff --git a/async/doc.go b/async/doc.go new file mode 100644 index 0000000..c0b8189 --- /dev/null +++ b/async/doc.go @@ -0,0 +1,3 @@ +// Package async provides asynchronous orchestration primitives for Go: +// promises, futures, and deferred actions. +package async diff --git a/concurrency/future_action.go b/async/future_action.go similarity index 98% rename from concurrency/future_action.go rename to async/future_action.go index 09cd0ad..d607830 100644 --- a/concurrency/future_action.go +++ b/async/future_action.go @@ -1,4 +1,4 @@ -package concurrency +package async // FutureAction is an abstraction over a channel that models a task and its result. // It allows executing a computation asynchronously in a goroutine and retrieving diff --git a/concurrency/future_action_test.go b/async/future_action_test.go similarity index 72% rename from concurrency/future_action_test.go rename to async/future_action_test.go index bda9650..5f046e3 100644 --- a/concurrency/future_action_test.go +++ b/async/future_action_test.go @@ -1,4 +1,4 @@ -package concurrency_test +package async_test import ( "testing" @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/lif0/pkg/concurrency" + "github.com/lif0/pkg/async" ) func Test_FutureAction(t *testing.T) { @@ -15,7 +15,7 @@ func Test_FutureAction(t *testing.T) { return "success" } - future := concurrency.NewFutureAction(callback) + future := async.NewFutureAction(callback) time.Sleep(time.Millisecond * 500) result := future.Get() assert.Equal(t, "success", result) diff --git a/concurrency/promise_with_future.go b/async/promise_with_future.go similarity index 99% rename from concurrency/promise_with_future.go rename to async/promise_with_future.go index c095f88..58481c4 100644 --- a/concurrency/promise_with_future.go +++ b/async/promise_with_future.go @@ -1,4 +1,4 @@ -package concurrency +package async import ( "sync" diff --git a/concurrency/promise_with_future_test.go b/async/promise_with_future_test.go similarity index 86% rename from concurrency/promise_with_future_test.go rename to async/promise_with_future_test.go index 927281f..e488672 100644 --- a/concurrency/promise_with_future_test.go +++ b/async/promise_with_future_test.go @@ -1,4 +1,4 @@ -package concurrency_test +package async_test import ( "errors" @@ -6,11 +6,11 @@ import ( "testing" "time" - "github.com/lif0/pkg/concurrency" + "github.com/lif0/pkg/async" ) func TestPromiseSet(t *testing.T) { - p := concurrency.NewPromise[string]() + p := async.NewPromise[string]() p.Set("test") f := p.GetFuture() @@ -21,7 +21,7 @@ func TestPromiseSet(t *testing.T) { } func TestPromiseSetMultiple(t *testing.T) { - p := concurrency.NewPromise[string]() + p := async.NewPromise[string]() p.Set("first") p.Set("second") // Should be ignored. @@ -33,7 +33,7 @@ func TestPromiseSetMultiple(t *testing.T) { } func TestGetFuture(t *testing.T) { - p := concurrency.NewPromise[string]() + p := async.NewPromise[string]() p.Set("test") f := p.GetFuture() @@ -48,7 +48,7 @@ func TestNewFuture(t *testing.T) { ch <- "test" close(ch) - f := concurrency.NewFuture[string](ch) + f := async.NewFuture[string](ch) value := f.Get() if value != "test" { t.Errorf("NewFuture: expected value 'test', got '%s'", value) @@ -56,7 +56,7 @@ func TestNewFuture(t *testing.T) { } func TestFutureGet(t *testing.T) { - p := concurrency.NewPromise[string]() + p := async.NewPromise[string]() go func() { time.Sleep(time.Millisecond * 50) p.Set("test") @@ -72,7 +72,7 @@ func TestFutureGet(t *testing.T) { func TestFutureGetEmptyChannel(t *testing.T) { ch := make(chan string, 1) close(ch) - f := concurrency.NewFuture[string](ch) + f := async.NewFuture[string](ch) value := f.Get() if value != "" { t.Errorf("Get: expected zero value for closed empty channel, got '%s'", value) @@ -80,7 +80,7 @@ func TestFutureGetEmptyChannel(t *testing.T) { } func TestPromiseError(t *testing.T) { - p := concurrency.NewPromise[error]() + p := async.NewPromise[error]() expectedErr := errors.New("test error") go func() { time.Sleep(time.Millisecond * 50) @@ -95,7 +95,7 @@ func TestPromiseError(t *testing.T) { } func TestConcurrentSet(t *testing.T) { - p := concurrency.NewPromise[string]() + p := async.NewPromise[string]() var wg sync.WaitGroup n := 10 wg.Add(n) diff --git a/concurrency/chanx/empty.go b/chanx/empty.go similarity index 100% rename from concurrency/chanx/empty.go rename to chanx/empty.go diff --git a/concurrency/chanx/fan_in.go b/chanx/fan_in.go similarity index 100% rename from concurrency/chanx/fan_in.go rename to chanx/fan_in.go diff --git a/concurrency/chanx/fan_in_test.go b/chanx/fan_in_test.go similarity index 99% rename from concurrency/chanx/fan_in_test.go rename to chanx/fan_in_test.go index 16f4957..1ac1dae 100644 --- a/concurrency/chanx/fan_in_test.go +++ b/chanx/fan_in_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - "github.com/lif0/pkg/concurrency/chanx" + "github.com/lif0/pkg/chanx" "github.com/stretchr/testify/assert" ) diff --git a/concurrency/chanx/helpers.go b/chanx/helpers.go similarity index 100% rename from concurrency/chanx/helpers.go rename to chanx/helpers.go diff --git a/concurrency/chanx/helpers_test.go b/chanx/helpers_test.go similarity index 98% rename from concurrency/chanx/helpers_test.go rename to chanx/helpers_test.go index 1bbed80..ed3c22f 100644 --- a/concurrency/chanx/helpers_test.go +++ b/chanx/helpers_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/lif0/pkg/concurrency/chanx" + "github.com/lif0/pkg/chanx" ) // TestToRecvChans verifies that ToRecvChans converts a slice of bidirectional channels to receive-only. diff --git a/concurrency/CHANGELOG.md b/concurrency/CHANGELOG.md deleted file mode 100644 index bd48457..0000000 --- a/concurrency/CHANGELOG.md +++ /dev/null @@ -1,31 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [Unreleased] YYYY-MM-DD -### Added -### Fixed -### Changed - -## [v1.2.0] 2025-10-29 -### Added -- [[PKG-20]](https://github.com/lif0/pkg/issues/28) Add SyncValue[T]; by @lif0 - -## [v1.1.0] -### Added -- [PKG-1](https://github.com/lif0/pkg/issues/1) Add `chanx.FanIn` pattern. -### Fixed -### Changed - -## [v1.0.1] -### Added -- [PKG-11](https://github.com/lif0/pkg/issues/11) Introduce `FutureAction` pattern. -### Fixed -### Changed - -## [v1.0.0] -### Added -- [PKG-3](https://github.com/lif0/pkg/issues/3) Add `WithLock` for concurrent execution using `sync.Locker` -- [PKG-4](https://github.com/lif0/pkg/issues/4) Add `Semaphore` type to limiting the number of concurrent holders of a shared resource. \ No newline at end of file diff --git a/concurrency/README.md b/concurrency/README.md deleted file mode 100644 index f2fe921..0000000 --- a/concurrency/README.md +++ /dev/null @@ -1,652 +0,0 @@ -# package concurrency - -[![build](https://github.com/lif0/pkg/workflows/build/badge.svg)](https://github.com/lif0/pkg/workflows/build/badge.svg) -[![go reference](https://pkg.go.dev/badge/github.com/lif0/pkg.svg)](https://pkg.go.dev/github.com/lif0/pkg/concurrency) -![last version](https://img.shields.io/github/v/tag/lif0/pkg?label=latest&filter=concurrency/*) -[![concurrency coverage](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Flif0%2Fpkg%2Frefs%2Fheads%2Fmain%2F.github%2Fassets%2Fbadges%2Fcoverage-concurrency.json)](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Flif0%2Fpkg%2Frefs%2Fheads%2Fmain%2F.github%2Fassets%2Fbadges%2Fcoverage-concurrency.json) -[![concurrency report card](https://goreportcard.com/badge/github.com/lif0/pkg/concurrency)](https://goreportcard.com/report/github.com/lif0/pkg/concurrency) - -## Contents - -- [Overview](#-overview) -- [Requirements](#️-requirements) -- [Installation](#-installation) -- [Features](#-features) - - [Semaphore](#semaphore) - - [WithLock](#withlock) - - [FutureAction](#futureaction) - - [Promise](#promise) - - [SyncValue](#syncvalue) - - [MutateValue()](#mutatevalue) - - [ReadValue()](#readvalue) - - [Benchmark](#benchmark) - - [Examples](#examples) -- [Package: `chanx`](#package-chanx-channel-extension) - - [FanIn](#fanin) - - [ToRecvChans](#torecvchans) - - [ToSendChans](#tosendchans) -- [Roadmap](#️-roadmap) -- [License](#-license) - ---- - -## 📋 Overview - -The `concurrency` package provides lightweight, efficient concurrency primitives for Go, designed for correctness and performance with minimal memory allocations. It simplifies concurrent programming tasks in Go applications. - -For full documentation, see [https://pkg.go.dev/github.com/lif0/pkg/concurrency](https://pkg.go.dev/github.com/lif0/pkg/concurrency). - ---- - -## ⚙️ Requirements - -- **go 1.19 or higher** - -## 📦 Installation - -To add this package to your project, use `go get`: - -```bash -go get github.com/lif0/pkg/concurrency@latest -``` - -Import the reflect extension in your code: - -```go -import "github.com/lif0/pkg/concurrency" -``` - ---- - -## ✨ Features - -### Semaphore - -The `Semaphore` type provides a counting semaphore to limit the number of concurrent holders of a shared resource. It supports both limited and unlimited capacity, with methods like `Acquire`, `AcquireContext`, `TryAcquire`, `Release`, `InUse`, and `Cap`. - -#### Example: Limited Semaphore - -```go -package main - -import ( - "fmt" - "github.com/lif0/pkg/concurrency" -) - -func main() { - // Create a semaphore with a capacity of 3 - sem := concurrency.NewSemaphore(3) - - // Acquire a slot - sem.Acquire() - fmt.Printf("Acquired a slot, in use: %d/%d\\n", sem.InUse(), sem.Cap()) - - // Perform critical section work - // ... - - // Release the slot - sem.Release() - fmt.Println("Released a slot") -} -``` - -#### Example: Unlimited Semaphore - -```go -package main - -import ( - "fmt" - "github.com/lif0/pkg/concurrency" -) - -func main() { - // Create an unlimited semaphore - sem := concurrency.NewSemaphore(0) - - // Acquire is a no-op for unlimited semaphores - sem.Acquire() - fmt.Printf("Acquired (no-op), in use: %d, cap: %d\\n", sem.InUse(), sem.Cap()) - - // Perform work - // ... - - // Release is a no-op for unlimited semaphores - sem.Release() - fmt.Println("Released (no-op)") -} -``` - -#### Example: Context-Aware Acquisition - -```go -package main - -import ( - "context" - "fmt" - "time" - "github.com/lif0/pkg/concurrency" -) - -func main() { - // Create a semaphore with a capacity of 2 - sem := concurrency.NewSemaphore(2) - - // Create a context with a timeout - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) - defer cancel() - - // Attempt to acquire a slot with context - if err := sem.AcquireContext(ctx); err != nil { - fmt.Printf("Failed to acquire: %v\\n", err) - return - } - fmt.Printf("Acquired a slot with context, in use: %d/%d\\n", sem.InUse(), sem.Cap()) - - // Perform work - // ... - - // Release the slot - sem.Release() - fmt.Println("Released a slot") -} -``` - -#### Example: Non-Blocking Acquisition - -```go -package main - -import ( - "fmt" - "github.com/lif0/pkg/concurrency" -) - -func main() { - // Create a semaphore with a capacity of 1 - sem := concurrency.NewSemaphore(1) - - // Acquire the only slot - sem.Acquire() - fmt.Printf("Acquired a slot, in use: %d/%d\\n", sem.InUse(), sem.Cap()) - - // Try to acquire another slot without blocking - if sem.TryAcquire() { - fmt.Println("Acquired another slot") - } else { - fmt.Println("Failed to acquire: no slots available") - } - - // Release the slot - sem.Release() - fmt.Println("Released a slot") -} -``` - -### WithLock - -`WithLock` is a helper function that executes an action while holding a lock. -It guarantees that the lock will always be released, even if the action panics. - -```go -import ( - "github.com/lif0/pkg/concurrency" -) - -func main() { - var mu sync.Mutex - counter := 0 - var wg sync.WaitGroup - - for i := 0; i < 5; i++ { - wg.Add(1) - wg.Go(func() { - for j := 0; j < 100; j++ { - concurrency.WithLock(&mu, func() { - counter++ - }) - } - }) - } - - wg.Wait() - fmt.Println("Final counter:", counter) // Always 500 -} -``` - -### FutureAction - -The `FutureAction` type provides an abstraction over a channel that models a task and its result. It allows executing a computation asynchronously in a goroutine and retrieving the result later via a blocking call. This is similar to the Future pattern in other languages, providing a simple way to handle asynchronous results without manual channel management. - -The channel is closed after the result is sent, ensuring proper resource cleanup. - -#### Example: Basic Usage - -```go -package main - -import ( - "fmt" - "time" - - "github.com/lif0/pkg/concurrency" -) - -func main() { - callback := func() any { - time.Sleep(time.Second) - return "success" - } - - future := concurrency.NewFutureAction(callback) - result := future.Get() - fmt.Println(result) // Output: success -} -``` - -#### Example: Generic Type Usage - -```go -package main - -import ( - "fmt" - "time" - "github.com/lif0/pkg/concurrency" -) - -func main() { - callback := func() int { - time.Sleep(time.Second) - return 42 - } - - future := concurrency.NewFutureAction(callback) - result := future.Get() - fmt.Printf("Result: %d\n", result) // Output: Result: 42 -} -``` - -### Promise - -The `Promise` type represents a writable, single-assignment container for a future value. It allows setting a value exactly once (subsequent sets are ignored) and provides a `Future` for reading the value asynchronously. This is similar to the Promise/Future pattern in other languages, enabling clean handling of asynchronous results with thread safety via atomic operations and mutexes. - -The internal channel is buffered (capacity 1) and closed after setting the value. Aliases `PromiseError` and `FutureError` are provided for error handling. - -#### Example: Basic Usage - -```go -package main - -import ( - "fmt" - "time" - "github.com/lif0/pkg/concurrency" -) - -func main() { - promise := concurrency.NewPromise[string]() - go func() { - time.Sleep(time.Second) - promise.Set("Cake") - }() - - future := promise.GetFuture() - value := future.Get() - fmt.Println(value) // Output: Cake -} -``` - -#### Example: Error Handling with PromiseError - -```go -package main - -import ( - "errors" - "fmt" - "time" - "github.com/lif0/pkg/concurrency" -) - -func main() { - promise := concurrency.NewPromise[error]() - go func() { - time.Sleep(time.Second) - promise.Set(errors.New("Something went wrong")) - }() - - future := promise.GetFuture() - err := future.Get() - if err != nil { - fmt.Printf("Error: %v\n", err) // Output: Error: Something went wrong - } -} -``` - -#### Example: Wrapping Existing Channel with NewFuture - -```go -package main - -import ( - "fmt" - "github.com/lif0/pkg/concurrency" -) - -func main() { - ch := make(chan int, 1) - ch <- 42 - close(ch) - - future := concurrency.NewFuture(ch) - value := future.Get() - fmt.Printf("Value: %d\n", value) // Output: Value: 42 -} -``` - -### SyncValue - -SyncValue is a generic wrapper around a value of any type `T` that allows -concurrent access with safe read and write operations protected by an RWMutex. - -It provides two methods: `MutateValue` and `ReadValue`. - -- `MutateValue` gives exclusive write access to the wrapped value. -- `ReadValue` gives shared read access to the wrapped value. - -Inside `MutateValue`, mu.Lock() / mu.Unlock() are used. -Inside `ReadValue`, mu.RLock() / mu.RUnlock() are used. - -🍀 Use it always when you need `any+sync.Mutex` - -#### MutateValue - -- Use mu.Lock() / mu.Unlock() -- The pointer is only safe to use within the callback. -- **Do not store the pointer** beyond the duration of the callback. -- Avoid calling other methods of SyncValue from within the callback to prevent lock re-entrancy issues (Go mutexes are not re-entrant). - -#### ReadValue - -- Use mu.RLock() / mu.RUnlock() -- The pointer is only safe to use within the callback. -- **Do not store the pointer** beyond the duration of the callback. -- If `T` (or its fields) contains reference types (e.g., slices/maps), copying *v will be shallow. To safely use the value after the callback returns, make a defensive deep copy. - -#### Benchmark - -```bash -goos: darwin -goarch: arm64 -pkg: github.com/lif0/pkg/concurrency -cpu: Apple M2 -``` - -**SyncValue[int64] vs Atomic.Int64:** - -```bash -Benchmark_Int64_Mixed/SyncValue-8 36694729 32.53 ns/op 0 B/op 0 allocs/op -Benchmark_Int64_Mixed/Atomic.Int64-8 471930460 2.649 ns/op 0 B/op 0 allocs/op -``` - -**SyncValue[complex] vs Atomic.Value/Pointer:** - -```bash -Benchmark_Complex_Mixed/SyncValue-8 14479608 82.42 ns/op 22 B/op 0 allocs/op -Benchmark_Complex_Mixed/Atomic.Value-8 1000000 1247 ns/op 28952 B/op 0 allocs/op -``` - -#### Examples - -##### Example: with simple type - -```go -import "github.com/lif0/pkg/concurrency" - - -func main() { - sv = concurrency.NewSyncValue[int]() - - sv.MutateValue(func(v *int) { *v++ }) - - var out int - c.sv.ReadValue(func(v *int) { out = *v }) // safeCopy - - fmt.Println(out) // will be print `1` -} -``` - -##### Example: with slice - -```go -import "github.com/lif0/pkg/concurrency" - - -func main() { - sv = concurrency.NewSyncValue[[]int]([]int{}) - - sv.MutateValue(func(v *int) { *v = append(*v, 10) }) - - var out []int - c.sv.ReadValue(func(v *int) { - out = make([]int, len(*v)) // alloc slice (because copy don't do that) - copy(out, *v) - }) - - fmt.Println(out) // will be print `[10]` -} -``` - -##### Example: with complex type - -```go -import "github.com/lif0/pkg/concurrency" - -type User struct { - ID string - Roles []string -} - -type State struct { - Users map[string]User -} - -func main() { - sv := concurrency.NewSyncValue[User](State{ - Users: make(map[string]User), - }) - - sv.MutateValue(func(s *State) { - s.Users["u1"] = User{ID: "u1", Roles: []string{"reader"}} - s.Users["u2"] = User{ID: "u2", Roles: []string{"writer", "admin"}} - }) - - var usersSnap map[string]User - sv.ReadValue(func(s *State) { - usersSnap = make(map[string]User, len(s.Users)) - for id, u := range s.Users { - // make a deep copy of Roles; otherwise the underlying array would be shared. - usersSnap[id] = User{ - ID: u.ID, - Roles: append([]string(nil), u.Roles...), - } - - // OR - // usersSnap[id] = make([]string, len(u.Roles)) - // copy(usersSnap[id].Roles, u.Roles) - } - }) - - fmt.Println("users snapshot:", usersSnap) -} -``` - -##### Example: Race. Incorrect example - -```go -import "github.com/lif0/pkg/concurrency" - -func main() { - // BAD: race on slice due to shallow copy of the slice header - sv := concurrency.NewSyncValue([]int{1, 2, 3}) - - // ❌ BAD: store a shallow copy of the slice header outside the callback. - // After the callback returns, `shared` still points to the same underlying array - // as the internal value inside SyncValue. - var shared []int - sv.ReadValue(func(v *[]int) { - shared = *v // SHALLOW COPY: ptr/len/cap copied, but the array is shared. - }) -} -``` - -## Package `chanx`: Channel Extension - -The `chanx` subpackage provides extension for working with channels. - -### FanIn - -`FanIn` merges multiple input channels into a single output channel. It reads concurrently from each input channel and forwards values to the output. The output channel is closed when all input channels are closed or the context is canceled. This is a non-blocking, concurrent fan-in implementation that respects context cancellation. The order of values in the output is not guaranteed. - -#### Example: Basic Usage - -```go -package main - -import ( - "context" - "fmt" - - "github.com/lif0/pkg/concurrency/chanx" -) - -func main() { - ctx := context.Background() - ch1 := make(chan string) - ch2 := make(chan string) - - go func() { - ch1 <- "from ch1" - close(ch1) - }() - go func() { - ch2 <- "from ch2" - close(ch2) - }() - - out := chanx.FanIn(ctx, ch1, ch2) - for v := range out { - fmt.Println(v) // Output may vary: from ch1, from ch2 - } -} -``` - -#### Example: Concurrent Usage with ToRecvChans - -```go -package main - -import ( - "context" - "fmt" - - "github.com/lif0/pkg/concurrency/chanx" -) - -func main() { - ctx := context.Background() - chans := make([]chan int, 10) - - for i := 0; i < len(chans); i++ { - chans[i] = make(chan int) - go func(ch chan int) { - defer close(ch) - ch <- 1 - ch <- 2 - }(chans[i]) - } - - out := chanx.FanIn(ctx, chanx.ToRecvChans(chans)...) - sum := 0 - for v := range out { - sum += v - } - fmt.Println("Sum:", sum) // Output: Sum: 30 -} -``` - -### ToRecvChans - -`ToRecvChans` converts a slice of bidirectional channels to a slice of receive-only channels. This ensures safe passing to functions expecting read-only channels. - -Complexity: time O(n), memory O(n). - -#### Example - -```go -package main - -import ( - "fmt" - - "github.com/lif0/pkg/concurrency/chanx" -) - -func main() { - chans := []chan int{make(chan int), make(chan int)} - recvChans := chanx.ToRecvChans(chans) - fmt.Printf("Type: %T\n", recvChans) // Output: Type: []<-chan int -} -``` - -### ToSendChans - -`ToSendChans` converts a slice of bidirectional channels to a slice of send-only channels. This ensures safe passing to functions expecting write-only channels. - -Complexity: time O(n), memory O(n). - -#### Example - -```go -package main - -import ( - "fmt" - - "github.com/lif0/pkg/concurrency/chanx" -) - -func main() { - chans := []chan string{make(chan string), make(chan string)} - sendChans := chanx.ToSendChans(chans) - fmt.Printf("Type: %T\n", sendChans) // Output: Type: []chan<- string -} -``` - -## 🗺️ Roadmap - -- [ ] Channel extensions - - [x] FanIn pattern - - [ ] FanOut pattern - - [ ] Dynamic select - - [ ] Transform pattern -- [x] Semaphore structure -- [x] WithLock extension -- [x] Future construct for asynchronous programming -- [x] Promise construct for asynchronous programming -- [x] Add SyncValue -- [ ] Add Watcher -- [ ] Michael-Scott Queue (MS Queue) for lock-free concurrent queues - ---- - -Contributions and feature suggestions are welcome 🤗. - ---- - -## 📄 License - -[MIT](./LICENSE) diff --git a/concurrency/empty.go b/concurrency/empty.go deleted file mode 100644 index 2f4e59c..0000000 --- a/concurrency/empty.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package concurrency provides concurrency utilities. -package concurrency diff --git a/concurrency/go.mod b/concurrency/go.mod deleted file mode 100644 index e5b9d4e..0000000 --- a/concurrency/go.mod +++ /dev/null @@ -1,11 +0,0 @@ -module github.com/lif0/pkg/concurrency - -go 1.19 - -require github.com/stretchr/testify v1.11.1 - -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) diff --git a/concurrency/go.sum b/concurrency/go.sum deleted file mode 100644 index c4c1710..0000000 --- a/concurrency/go.sum +++ /dev/null @@ -1,10 +0,0 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= -github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/utils/errx/multi_error.go b/errx/multi_error.go similarity index 100% rename from utils/errx/multi_error.go rename to errx/multi_error.go diff --git a/utils/errx/multi_error_test.go b/errx/multi_error_test.go similarity index 98% rename from utils/errx/multi_error_test.go rename to errx/multi_error_test.go index c933e57..f6e2c9c 100644 --- a/utils/errx/multi_error_test.go +++ b/errx/multi_error_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/lif0/pkg/utils/errx" + "github.com/lif0/pkg/errx" "github.com/stretchr/testify/assert" ) diff --git a/sync/go.mod b/go.mod similarity index 86% rename from sync/go.mod rename to go.mod index ea8bfe8..907f692 100644 --- a/sync/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ -module github.com/lif0/pkg/sync +module github.com/lif0/pkg -go 1.19 +go 1.23 require ( github.com/petermattis/goid v0.0.0-20250904145737-900bdf8bb490 diff --git a/sync/go.sum b/go.sum similarity index 100% rename from sync/go.sum rename to go.sum diff --git a/utils/internal/chain.go b/internal/chain.go similarity index 100% rename from utils/internal/chain.go rename to internal/chain.go diff --git a/utils/internal/chain_test.go b/internal/chain_test.go similarity index 99% rename from utils/internal/chain_test.go rename to internal/chain_test.go index 28b5acc..f90475a 100644 --- a/utils/internal/chain_test.go +++ b/internal/chain_test.go @@ -3,7 +3,7 @@ package internal_test import ( "testing" - "github.com/lif0/pkg/utils/internal" + "github.com/lif0/pkg/internal" "github.com/stretchr/testify/assert" ) diff --git a/reflectx/doc.go b/reflectx/doc.go new file mode 100644 index 0000000..7b653ce --- /dev/null +++ b/reflectx/doc.go @@ -0,0 +1,3 @@ +// Package reflectx provides reflection-based helpers that extend the standard +// library reflect package, such as estimating the in-memory payload of a value. +package reflectx diff --git a/utils/reflect/estimate_payload.go b/reflectx/estimate_payload.go similarity index 99% rename from utils/reflect/estimate_payload.go rename to reflectx/estimate_payload.go index f8006bc..179c948 100644 --- a/utils/reflect/estimate_payload.go +++ b/reflectx/estimate_payload.go @@ -1,4 +1,4 @@ -package reflect +package reflectx import ( "reflect" diff --git a/utils/reflect/estimate_payload_bench_out.txt b/reflectx/estimate_payload_bench_out.txt similarity index 100% rename from utils/reflect/estimate_payload_bench_out.txt rename to reflectx/estimate_payload_bench_out.txt diff --git a/utils/reflect/estimate_payload_bench_test.go b/reflectx/estimate_payload_bench_test.go similarity index 76% rename from utils/reflect/estimate_payload_bench_test.go rename to reflectx/estimate_payload_bench_test.go index 85cf922..a4d13d3 100644 --- a/utils/reflect/estimate_payload_bench_test.go +++ b/reflectx/estimate_payload_bench_test.go @@ -1,4 +1,4 @@ -package reflect_test +package reflectx_test import ( "fmt" @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/lif0/pkg/utils/reflect" + "github.com/lif0/pkg/reflectx" ) func BenchmarkEstimatePayloadOf(b *testing.B) { @@ -91,8 +91,8 @@ func benchmarkEstimateSizeOf[T any](b *testing.B, getValue func() T) { b.Run(TName, func(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - res := reflect.EstimatePayloadOf(val) - if res == reflect.ErrFailEstimatePayload { + res := reflectx.EstimatePayloadOf(val) + if res == reflectx.ErrFailEstimatePayload { fmt.Println(TName + " miss switch") } } @@ -101,8 +101,8 @@ func benchmarkEstimateSizeOf[T any](b *testing.B, getValue func() T) { b.Run("*"+TName, func(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - res := reflect.EstimatePayloadOf(ptrVal) - if res == reflect.ErrFailEstimatePayload { + res := reflectx.EstimatePayloadOf(ptrVal) + if res == reflectx.ErrFailEstimatePayload { fmt.Println(TName + " miss switch") } } @@ -112,8 +112,8 @@ func benchmarkEstimateSizeOf[T any](b *testing.B, getValue func() T) { b.Run("[]"+TName, func(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - res := reflect.EstimatePayloadOf(sliceValAny) - if res == reflect.ErrFailEstimatePayload { + res := reflectx.EstimatePayloadOf(sliceValAny) + if res == reflectx.ErrFailEstimatePayload { fmt.Println(TName + " miss switch") } } @@ -123,8 +123,8 @@ func benchmarkEstimateSizeOf[T any](b *testing.B, getValue func() T) { b.Run("*[]"+TName, func(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - res := reflect.EstimatePayloadOf(ptrSliceVal) - if res == reflect.ErrFailEstimatePayload { + res := reflectx.EstimatePayloadOf(ptrSliceVal) + if res == reflectx.ErrFailEstimatePayload { fmt.Println(TName + " miss switch") } } @@ -134,8 +134,8 @@ func benchmarkEstimateSizeOf[T any](b *testing.B, getValue func() T) { b.Run("[]*"+TName, func(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - res := reflect.EstimatePayloadOf(slicePrtValAny) - if res == reflect.ErrFailEstimatePayload { + res := reflectx.EstimatePayloadOf(slicePrtValAny) + if res == reflectx.ErrFailEstimatePayload { fmt.Println(TName + " miss switch") } } @@ -145,8 +145,8 @@ func benchmarkEstimateSizeOf[T any](b *testing.B, getValue func() T) { b.Run("*[]*"+TName, func(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - res := reflect.EstimatePayloadOf(prtSlicePrtVal) - if res == reflect.ErrFailEstimatePayload { + res := reflectx.EstimatePayloadOf(prtSlicePrtVal) + if res == reflectx.ErrFailEstimatePayload { fmt.Println(TName + " miss switch") } } @@ -156,8 +156,8 @@ func benchmarkEstimateSizeOf[T any](b *testing.B, getValue func() T) { b.Run("[100]"+TName, func(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - res := reflect.EstimatePayloadOf(arrayValAny) - if res == reflect.ErrFailEstimatePayload { + res := reflectx.EstimatePayloadOf(arrayValAny) + if res == reflectx.ErrFailEstimatePayload { fmt.Println(TName + " miss switch") } } @@ -167,8 +167,8 @@ func benchmarkEstimateSizeOf[T any](b *testing.B, getValue func() T) { b.Run("*[100]"+TName, func(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - res := reflect.EstimatePayloadOf(ptrArrayVal) - if res == reflect.ErrFailEstimatePayload { + res := reflectx.EstimatePayloadOf(ptrArrayVal) + if res == reflectx.ErrFailEstimatePayload { fmt.Println(TName + " miss switch") } } @@ -178,8 +178,8 @@ func benchmarkEstimateSizeOf[T any](b *testing.B, getValue func() T) { b.Run("[100]*"+TName, func(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - res := reflect.EstimatePayloadOf(arrayPrtVal) - if res == reflect.ErrFailEstimatePayload { + res := reflectx.EstimatePayloadOf(arrayPrtVal) + if res == reflectx.ErrFailEstimatePayload { fmt.Println(TName + " miss switch") } } @@ -189,8 +189,8 @@ func benchmarkEstimateSizeOf[T any](b *testing.B, getValue func() T) { b.Run("*[100]*"+TName, func(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - res := reflect.EstimatePayloadOf(prtArrayPrtVal) - if res == reflect.ErrFailEstimatePayload { + res := reflectx.EstimatePayloadOf(prtArrayPrtVal) + if res == reflectx.ErrFailEstimatePayload { fmt.Println(TName + " miss switch") } } @@ -203,8 +203,8 @@ func benchmarkEstimateSizeOf[T any](b *testing.B, getValue func() T) { b.ResetTimer() for i := 0; i < b.N; i++ { var arg []T - res := reflect.EstimatePayloadOf(arg) - if res == reflect.ErrFailEstimatePayload { + res := reflectx.EstimatePayloadOf(arg) + if res == reflectx.ErrFailEstimatePayload { fmt.Println(TName + " miss switch") } } @@ -215,8 +215,8 @@ func benchmarkEstimateSizeOf[T any](b *testing.B, getValue func() T) { b.ResetTimer() for i := 0; i < b.N; i++ { var arg *[]T - res := reflect.EstimatePayloadOf(arg) - if res == reflect.ErrFailEstimatePayload { + res := reflectx.EstimatePayloadOf(arg) + if res == reflectx.ErrFailEstimatePayload { fmt.Println(TName + " miss switch") } } @@ -227,8 +227,8 @@ func benchmarkEstimateSizeOf[T any](b *testing.B, getValue func() T) { b.ResetTimer() for i := 0; i < b.N; i++ { var arg []*T - res := reflect.EstimatePayloadOf(arg) - if res == reflect.ErrFailEstimatePayload { + res := reflectx.EstimatePayloadOf(arg) + if res == reflectx.ErrFailEstimatePayload { fmt.Println(TName + " miss switch") } } @@ -239,8 +239,8 @@ func benchmarkEstimateSizeOf[T any](b *testing.B, getValue func() T) { b.ResetTimer() for i := 0; i < b.N; i++ { var arg []*T - res := reflect.EstimatePayloadOf(&arg) - if res == reflect.ErrFailEstimatePayload { + res := reflectx.EstimatePayloadOf(&arg) + if res == reflectx.ErrFailEstimatePayload { fmt.Println(TName + " miss switch") } } @@ -251,8 +251,8 @@ func benchmarkEstimateSizeOf[T any](b *testing.B, getValue func() T) { b.ResetTimer() for i := 0; i < b.N; i++ { var arg [100]T - res := reflect.EstimatePayloadOf(arg) - if res == reflect.ErrFailEstimatePayload { + res := reflectx.EstimatePayloadOf(arg) + if res == reflectx.ErrFailEstimatePayload { fmt.Println(TName + " miss switch") } } @@ -263,8 +263,8 @@ func benchmarkEstimateSizeOf[T any](b *testing.B, getValue func() T) { b.ResetTimer() for i := 0; i < b.N; i++ { var arg *[100]T - res := reflect.EstimatePayloadOf(arg) - if res == reflect.ErrFailEstimatePayload { + res := reflectx.EstimatePayloadOf(arg) + if res == reflectx.ErrFailEstimatePayload { fmt.Println(TName + " miss switch") } } @@ -275,8 +275,8 @@ func benchmarkEstimateSizeOf[T any](b *testing.B, getValue func() T) { b.ResetTimer() for i := 0; i < b.N; i++ { var arg [100]*T - res := reflect.EstimatePayloadOf(arg) - if res == reflect.ErrFailEstimatePayload { + res := reflectx.EstimatePayloadOf(arg) + if res == reflectx.ErrFailEstimatePayload { fmt.Println(TName + " miss switch") } } @@ -287,8 +287,8 @@ func benchmarkEstimateSizeOf[T any](b *testing.B, getValue func() T) { b.ResetTimer() for i := 0; i < b.N; i++ { var arg *[100]*T - res := reflect.EstimatePayloadOf(arg) - if res == reflect.ErrFailEstimatePayload { + res := reflectx.EstimatePayloadOf(arg) + if res == reflectx.ErrFailEstimatePayload { fmt.Println(TName + " miss switch") } } diff --git a/utils/reflect/estimate_payload_test.go b/reflectx/estimate_payload_test.go similarity index 80% rename from utils/reflect/estimate_payload_test.go rename to reflectx/estimate_payload_test.go index f086482..d6551ca 100644 --- a/utils/reflect/estimate_payload_test.go +++ b/reflectx/estimate_payload_test.go @@ -1,11 +1,11 @@ -package reflect_test +package reflectx_test import ( "testing" "time" "unsafe" - "github.com/lif0/pkg/utils/reflect" + "github.com/lif0/pkg/reflectx" ) var ( @@ -33,7 +33,7 @@ var ( type CustomStruct struct{} func TestEstimatePayloadOf_nil(t *testing.T) { - got := reflect.EstimatePayloadOf(nil) + got := reflectx.EstimatePayloadOf(nil) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -43,7 +43,7 @@ func TestEstimatePayloadOf_nil(t *testing.T) { func TestEstimatePayloadOf_int(t *testing.T) { t.Run("int", func(t *testing.T) { v := int(42) - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := szInt if got != want { t.Errorf("got %d, want %d", got, want) @@ -52,7 +52,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { t.Run("*int", func(t *testing.T) { v := int(42) pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := szInt if got != want { t.Errorf("got %d, want %d", got, want) @@ -60,7 +60,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { }) t.Run("*int_nil", func(t *testing.T) { var pv *int = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -68,7 +68,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { }) t.Run("[]int", func(t *testing.T) { v := []int{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szInt if got != want { t.Errorf("got %d, want %d", got, want) @@ -76,7 +76,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { }) t.Run("[]int empty", func(t *testing.T) { v := []int{} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -84,7 +84,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { }) t.Run("[]int nil", func(t *testing.T) { var v []int = nil - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -93,7 +93,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { t.Run("*[]int non-nil", func(t *testing.T) { s := []int{1, 2, 3} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 3 * szInt if got != want { t.Errorf("got %d, want %d", got, want) @@ -101,7 +101,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { }) t.Run("*[]int nil", func(t *testing.T) { var ps *[]int = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -110,7 +110,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { t.Run("[]*int", func(t *testing.T) { a, b, c := int(1), int(2), int(3) v := []*int{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szInt if got != want { t.Errorf("got %d, want %d", got, want) @@ -119,7 +119,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { t.Run("[]*int with nil", func(t *testing.T) { a, b := int(1), int(2) v := []*int{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szInt if got != want { t.Errorf("got %d, want %d", got, want) @@ -127,7 +127,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { }) t.Run("[]*int nil", func(t *testing.T) { var v []*int = nil - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -135,7 +135,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { }) t.Run("[]*int all nil", func(t *testing.T) { v := []*int{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -145,7 +145,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { a, b := int(1), int(2) s := []*int{&a, nil, &b} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szInt if got != want { t.Errorf("got %d, want %d", got, want) @@ -153,7 +153,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { }) t.Run("*[]*int nil", func(t *testing.T) { var ps *[]*int = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -161,7 +161,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { }) t.Run("[3]int", func(t *testing.T) { v := [3]int{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szInt if got != want { t.Errorf("got %d, want %d", got, want) @@ -170,7 +170,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { t.Run("*[3]int non-nil", func(t *testing.T) { v := [3]int{1, 2, 3} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 3 * szInt if got != want { t.Errorf("got %d, want %d", got, want) @@ -178,7 +178,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { }) t.Run("*[3]int nil", func(t *testing.T) { var pv *[3]int = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -187,7 +187,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { t.Run("[3]*int", func(t *testing.T) { a, b, c := int(1), int(2), int(3) v := [3]*int{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szInt if got != want { t.Errorf("got %d, want %d", got, want) @@ -196,7 +196,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { t.Run("[3]*int with nil", func(t *testing.T) { a, b := int(1), int(2) v := [3]*int{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szInt if got != want { t.Errorf("got %d, want %d", got, want) @@ -204,7 +204,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { }) t.Run("[3]*int all nil", func(t *testing.T) { v := [3]*int{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -214,7 +214,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { a, b := int(1), int(2) v := [3]*int{&a, nil, &b} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 2 * szInt if got != want { t.Errorf("got %d, want %d", got, want) @@ -222,7 +222,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { }) t.Run("*[3]*int nil", func(t *testing.T) { var pv *[3]*int = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -230,7 +230,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { }) t.Run("[100]int", func(t *testing.T) { var v [100]int - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 100 * szInt if got != want { t.Errorf("got %d, want %d", got, want) @@ -238,7 +238,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { }) t.Run("*[100]int nil", func(t *testing.T) { var pv *[100]int = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -246,7 +246,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { }) t.Run("[100]*int all nil", func(t *testing.T) { var v [100]*int - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -254,7 +254,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { }) t.Run("*[100]*int nil", func(t *testing.T) { var pv *[100]*int = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -265,7 +265,7 @@ func TestEstimatePayloadOf_int(t *testing.T) { func TestEstimatePayloadOf_int8(t *testing.T) { t.Run("int8", func(t *testing.T) { v := int8(42) - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := szInt8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -274,7 +274,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { t.Run("*int8 non-nil", func(t *testing.T) { v := int8(42) pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := szInt8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -282,7 +282,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { }) t.Run("*int8 nil", func(t *testing.T) { var pv *int8 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -290,7 +290,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { }) t.Run("[]int8", func(t *testing.T) { v := []int8{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szInt8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -298,7 +298,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { }) t.Run("[]int8 empty", func(t *testing.T) { v := []int8{} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -306,7 +306,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { }) t.Run("[]int8 nil", func(t *testing.T) { var v []int8 = nil - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -315,7 +315,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { t.Run("*[]int8 non-nil", func(t *testing.T) { s := []int8{1, 2, 3} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 3 * szInt8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -323,7 +323,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { }) t.Run("*[]int8 nil", func(t *testing.T) { var ps *[]int8 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -332,7 +332,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { t.Run("[]*int8", func(t *testing.T) { a, b, c := int8(1), int8(2), int8(3) v := []*int8{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szInt8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -341,7 +341,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { t.Run("[]*int8 with nil", func(t *testing.T) { a, b := int8(1), int8(2) v := []*int8{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szInt8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -349,7 +349,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { }) t.Run("[]*int8 all nil", func(t *testing.T) { v := []*int8{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -359,7 +359,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { a, b := int8(1), int8(2) s := []*int8{&a, nil, &b} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szInt8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -367,7 +367,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { }) t.Run("*[]*int8 nil", func(t *testing.T) { var ps *[]*int8 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -375,7 +375,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { }) t.Run("[3]int8", func(t *testing.T) { v := [3]int8{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szInt8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -384,7 +384,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { t.Run("*[3]int8 non-nil", func(t *testing.T) { v := [3]int8{1, 2, 3} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 3 * szInt8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -392,7 +392,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { }) t.Run("*[3]int8 nil", func(t *testing.T) { var pv *[3]int8 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -401,7 +401,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { t.Run("[3]*int8", func(t *testing.T) { a, b, c := int8(1), int8(2), int8(3) v := [3]*int8{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szInt8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -410,7 +410,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { t.Run("[3]*int8 with nil", func(t *testing.T) { a, b := int8(1), int8(2) v := [3]*int8{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szInt8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -418,7 +418,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { }) t.Run("[3]*int8 all nil", func(t *testing.T) { v := [3]*int8{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -428,7 +428,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { a, b := int8(1), int8(2) v := [3]*int8{&a, nil, &b} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 2 * szInt8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -436,7 +436,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { }) t.Run("*[3]*int8 nil", func(t *testing.T) { var pv *[3]*int8 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -444,7 +444,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { }) t.Run("[100]int8", func(t *testing.T) { var v [100]int8 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 100 * szInt8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -452,7 +452,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { }) t.Run("*[100]int8 nil", func(t *testing.T) { var pv *[100]int8 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -460,7 +460,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { }) t.Run("[100]*int8 all nil", func(t *testing.T) { var v [100]*int8 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -468,7 +468,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { }) t.Run("*[100]*int8 nil", func(t *testing.T) { var pv *[100]*int8 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -479,7 +479,7 @@ func TestEstimatePayloadOf_int8(t *testing.T) { func TestEstimatePayloadOf_int16(t *testing.T) { t.Run("int16", func(t *testing.T) { v := int16(42) - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := szInt16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -488,7 +488,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { t.Run("*int16 non-nil", func(t *testing.T) { v := int16(42) pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := szInt16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -496,7 +496,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { }) t.Run("*int16 nil", func(t *testing.T) { var pv *int16 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -504,7 +504,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { }) t.Run("[]int16", func(t *testing.T) { v := []int16{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szInt16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -512,7 +512,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { }) t.Run("[]int16 empty", func(t *testing.T) { v := []int16{} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -520,7 +520,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { }) t.Run("[]int16 nil", func(t *testing.T) { var v []int16 = nil - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -529,7 +529,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { t.Run("*[]int16 non-nil", func(t *testing.T) { s := []int16{1, 2, 3} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 3 * szInt16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -537,7 +537,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { }) t.Run("*[]int16 nil", func(t *testing.T) { var ps *[]int16 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -546,7 +546,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { t.Run("[]*int16", func(t *testing.T) { a, b, c := int16(1), int16(2), int16(3) v := []*int16{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szInt16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -555,7 +555,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { t.Run("[]*int16 with nil", func(t *testing.T) { a, b := int16(1), int16(2) v := []*int16{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szInt16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -563,7 +563,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { }) t.Run("[]*int16 all nil", func(t *testing.T) { v := []*int16{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -573,7 +573,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { a, b := int16(1), int16(2) s := []*int16{&a, nil, &b} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szInt16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -581,7 +581,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { }) t.Run("*[]*int16 nil", func(t *testing.T) { var ps *[]*int16 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -589,7 +589,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { }) t.Run("[3]int16", func(t *testing.T) { v := [3]int16{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szInt16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -598,7 +598,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { t.Run("*[3]int16 non-nil", func(t *testing.T) { v := [3]int16{1, 2, 3} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 3 * szInt16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -606,7 +606,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { }) t.Run("*[3]int16 nil", func(t *testing.T) { var pv *[3]int16 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -615,7 +615,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { t.Run("[3]*int16", func(t *testing.T) { a, b, c := int16(1), int16(2), int16(3) v := [3]*int16{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szInt16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -624,7 +624,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { t.Run("[3]*int16 with nil", func(t *testing.T) { a, b := int16(1), int16(2) v := [3]*int16{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szInt16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -632,7 +632,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { }) t.Run("[3]*int16 all nil", func(t *testing.T) { v := [3]*int16{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -642,7 +642,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { a, b := int16(1), int16(2) v := [3]*int16{&a, nil, &b} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 2 * szInt16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -650,7 +650,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { }) t.Run("*[3]*int16 nil", func(t *testing.T) { var pv *[3]*int16 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -658,7 +658,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { }) t.Run("[100]int16", func(t *testing.T) { var v [100]int16 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 100 * szInt16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -666,7 +666,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { }) t.Run("*[100]int16 nil", func(t *testing.T) { var pv *[100]int16 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -674,7 +674,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { }) t.Run("[100]*int16 all nil", func(t *testing.T) { var v [100]*int16 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -682,7 +682,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { }) t.Run("*[100]*int16 nil", func(t *testing.T) { var pv *[100]*int16 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -693,7 +693,7 @@ func TestEstimatePayloadOf_int16(t *testing.T) { func TestEstimatePayloadOf_int32(t *testing.T) { t.Run("int32", func(t *testing.T) { v := int32(42) - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := szInt32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -702,7 +702,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { t.Run("*int32 non-nil", func(t *testing.T) { v := int32(42) pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := szInt32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -710,7 +710,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { }) t.Run("*int32 nil", func(t *testing.T) { var pv *int32 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -718,7 +718,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { }) t.Run("[]int32", func(t *testing.T) { v := []int32{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szInt32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -726,7 +726,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { }) t.Run("[]int32 empty", func(t *testing.T) { v := []int32{} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -734,7 +734,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { }) t.Run("[]int32 nil", func(t *testing.T) { var v []int32 = nil - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -743,7 +743,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { t.Run("*[]int32 non-nil", func(t *testing.T) { s := []int32{1, 2, 3} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 3 * szInt32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -751,7 +751,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { }) t.Run("*[]int32 nil", func(t *testing.T) { var ps *[]int32 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -760,7 +760,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { t.Run("[]*int32", func(t *testing.T) { a, b, c := int32(1), int32(2), int32(3) v := []*int32{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szInt32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -769,7 +769,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { t.Run("[]*int32 with nil", func(t *testing.T) { a, b := int32(1), int32(2) v := []*int32{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szInt32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -777,7 +777,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { }) t.Run("[]*int32 all nil", func(t *testing.T) { v := []*int32{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -787,7 +787,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { a, b := int32(1), int32(2) s := []*int32{&a, nil, &b} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szInt32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -795,7 +795,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { }) t.Run("*[]*int32 nil", func(t *testing.T) { var ps *[]*int32 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -803,7 +803,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { }) t.Run("[3]int32", func(t *testing.T) { v := [3]int32{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szInt32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -812,7 +812,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { t.Run("*[3]int32 non-nil", func(t *testing.T) { v := [3]int32{1, 2, 3} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 3 * szInt32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -820,7 +820,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { }) t.Run("*[3]int32 nil", func(t *testing.T) { var pv *[3]int32 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -829,7 +829,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { t.Run("[3]*int32", func(t *testing.T) { a, b, c := int32(1), int32(2), int32(3) v := [3]*int32{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szInt32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -838,7 +838,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { t.Run("[3]*int32 with nil", func(t *testing.T) { a, b := int32(1), int32(2) v := [3]*int32{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szInt32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -846,7 +846,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { }) t.Run("[3]*int32 all nil", func(t *testing.T) { v := [3]*int32{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -856,7 +856,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { a, b := int32(1), int32(2) v := [3]*int32{&a, nil, &b} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 2 * szInt32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -864,7 +864,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { }) t.Run("*[3]*int32 nil", func(t *testing.T) { var pv *[3]*int32 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -872,7 +872,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { }) t.Run("[100]int32", func(t *testing.T) { var v [100]int32 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 100 * szInt32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -880,7 +880,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { }) t.Run("*[100]int32 nil", func(t *testing.T) { var pv *[100]int32 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -888,7 +888,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { }) t.Run("[100]*int32 all nil", func(t *testing.T) { var v [100]*int32 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -896,7 +896,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { }) t.Run("*[100]*int32 nil", func(t *testing.T) { var pv *[100]*int32 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -907,7 +907,7 @@ func TestEstimatePayloadOf_int32(t *testing.T) { func TestEstimatePayloadOf_int64(t *testing.T) { t.Run("int64", func(t *testing.T) { v := int64(42) - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := szInt64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -916,7 +916,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { t.Run("*int64 non-nil", func(t *testing.T) { v := int64(42) pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := szInt64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -924,7 +924,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { }) t.Run("*int64 nil", func(t *testing.T) { var pv *int64 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -932,7 +932,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { }) t.Run("[]int64", func(t *testing.T) { v := []int64{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szInt64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -940,7 +940,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { }) t.Run("[]int64 empty", func(t *testing.T) { v := []int64{} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -948,7 +948,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { }) t.Run("[]int64 nil", func(t *testing.T) { var v []int64 = nil - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -957,7 +957,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { t.Run("*[]int64 non-nil", func(t *testing.T) { s := []int64{1, 2, 3} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 3 * szInt64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -965,7 +965,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { }) t.Run("*[]int64 nil", func(t *testing.T) { var ps *[]int64 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -974,7 +974,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { t.Run("[]*int64", func(t *testing.T) { a, b, c := int64(1), int64(2), int64(3) v := []*int64{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szInt64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -983,7 +983,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { t.Run("[]*int64 with nil", func(t *testing.T) { a, b := int64(1), int64(2) v := []*int64{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szInt64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -991,7 +991,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { }) t.Run("[]*int64 all nil", func(t *testing.T) { v := []*int64{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1001,7 +1001,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { a, b := int64(1), int64(2) s := []*int64{&a, nil, &b} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szInt64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1009,7 +1009,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { }) t.Run("*[]*int64 nil", func(t *testing.T) { var ps *[]*int64 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1017,7 +1017,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { }) t.Run("[3]int64", func(t *testing.T) { v := [3]int64{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szInt64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1026,7 +1026,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { t.Run("*[3]int64 non-nil", func(t *testing.T) { v := [3]int64{1, 2, 3} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 3 * szInt64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1034,7 +1034,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { }) t.Run("*[3]int64 nil", func(t *testing.T) { var pv *[3]int64 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1043,7 +1043,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { t.Run("[3]*int64", func(t *testing.T) { a, b, c := int64(1), int64(2), int64(3) v := [3]*int64{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szInt64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1052,7 +1052,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { t.Run("[3]*int64 with nil", func(t *testing.T) { a, b := int64(1), int64(2) v := [3]*int64{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szInt64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1060,7 +1060,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { }) t.Run("[3]*int64 all nil", func(t *testing.T) { v := [3]*int64{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1070,7 +1070,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { a, b := int64(1), int64(2) v := [3]*int64{&a, nil, &b} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 2 * szInt64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1078,7 +1078,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { }) t.Run("*[3]*int64 nil", func(t *testing.T) { var pv *[3]*int64 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1086,7 +1086,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { }) t.Run("[100]int64", func(t *testing.T) { var v [100]int64 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 100 * szInt64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1094,7 +1094,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { }) t.Run("*[100]int64 nil", func(t *testing.T) { var pv *[100]int64 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1102,7 +1102,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { }) t.Run("[100]*int64 all nil", func(t *testing.T) { var v [100]*int64 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1110,7 +1110,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { }) t.Run("*[100]*int64 nil", func(t *testing.T) { var pv *[100]*int64 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1121,7 +1121,7 @@ func TestEstimatePayloadOf_int64(t *testing.T) { func TestEstimatePayloadOf_uint(t *testing.T) { t.Run("uint", func(t *testing.T) { v := uint(42) - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := szUint if got != want { t.Errorf("got %d, want %d", got, want) @@ -1130,7 +1130,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { t.Run("*uint non-nil", func(t *testing.T) { v := uint(42) pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := szUint if got != want { t.Errorf("got %d, want %d", got, want) @@ -1138,7 +1138,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { }) t.Run("*uint nil", func(t *testing.T) { var pv *uint = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1146,7 +1146,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { }) t.Run("[]uint", func(t *testing.T) { v := []uint{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUint if got != want { t.Errorf("got %d, want %d", got, want) @@ -1154,7 +1154,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { }) t.Run("[]uint empty", func(t *testing.T) { v := []uint{} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1162,7 +1162,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { }) t.Run("[]uint nil", func(t *testing.T) { var v []uint = nil - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1171,7 +1171,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { t.Run("*[]uint non-nil", func(t *testing.T) { s := []uint{1, 2, 3} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 3 * szUint if got != want { t.Errorf("got %d, want %d", got, want) @@ -1179,7 +1179,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { }) t.Run("*[]uint nil", func(t *testing.T) { var ps *[]uint = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1188,7 +1188,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { t.Run("[]*uint", func(t *testing.T) { a, b, c := uint(1), uint(2), uint(3) v := []*uint{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUint if got != want { t.Errorf("got %d, want %d", got, want) @@ -1197,7 +1197,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { t.Run("[]*uint with nil", func(t *testing.T) { a, b := uint(1), uint(2) v := []*uint{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szUint if got != want { t.Errorf("got %d, want %d", got, want) @@ -1205,7 +1205,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { }) t.Run("[]*uint all nil", func(t *testing.T) { v := []*uint{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1215,7 +1215,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { a, b := uint(1), uint(2) s := []*uint{&a, nil, &b} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szUint if got != want { t.Errorf("got %d, want %d", got, want) @@ -1223,7 +1223,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { }) t.Run("*[]*uint nil", func(t *testing.T) { var ps *[]*uint = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1231,7 +1231,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { }) t.Run("[3]uint", func(t *testing.T) { v := [3]uint{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUint if got != want { t.Errorf("got %d, want %d", got, want) @@ -1240,7 +1240,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { t.Run("*[3]uint non-nil", func(t *testing.T) { v := [3]uint{1, 2, 3} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 3 * szUint if got != want { t.Errorf("got %d, want %d", got, want) @@ -1248,7 +1248,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { }) t.Run("*[3]uint nil", func(t *testing.T) { var pv *[3]uint = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1257,7 +1257,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { t.Run("[3]*uint", func(t *testing.T) { a, b, c := uint(1), uint(2), uint(3) v := [3]*uint{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUint if got != want { t.Errorf("got %d, want %d", got, want) @@ -1266,7 +1266,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { t.Run("[3]*uint with nil", func(t *testing.T) { a, b := uint(1), uint(2) v := [3]*uint{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szUint if got != want { t.Errorf("got %d, want %d", got, want) @@ -1274,7 +1274,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { }) t.Run("[3]*uint all nil", func(t *testing.T) { v := [3]*uint{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1284,7 +1284,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { a, b := uint(1), uint(2) v := [3]*uint{&a, nil, &b} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 2 * szUint if got != want { t.Errorf("got %d, want %d", got, want) @@ -1292,7 +1292,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { }) t.Run("*[3]*uint nil", func(t *testing.T) { var pv *[3]*uint = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1300,7 +1300,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { }) t.Run("[100]uint", func(t *testing.T) { var v [100]uint - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 100 * szUint if got != want { t.Errorf("got %d, want %d", got, want) @@ -1308,7 +1308,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { }) t.Run("*[100]uint nil", func(t *testing.T) { var pv *[100]uint = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1316,7 +1316,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { }) t.Run("[100]*uint all nil", func(t *testing.T) { var v [100]*uint - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1324,7 +1324,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { }) t.Run("*[100]*uint nil", func(t *testing.T) { var pv *[100]*uint = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1335,7 +1335,7 @@ func TestEstimatePayloadOf_uint(t *testing.T) { func TestEstimatePayloadOf_uint8(t *testing.T) { t.Run("uint8", func(t *testing.T) { v := uint8(42) - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := szUint8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1344,7 +1344,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { t.Run("*uint8 non-nil", func(t *testing.T) { v := uint8(42) pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := szUint8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1352,7 +1352,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { }) t.Run("*uint8 nil", func(t *testing.T) { var pv *uint8 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1360,7 +1360,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { }) t.Run("[]uint8", func(t *testing.T) { v := []uint8{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUint8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1368,7 +1368,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { }) t.Run("[]uint8 empty", func(t *testing.T) { v := []uint8{} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1376,7 +1376,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { }) t.Run("[]uint8 nil", func(t *testing.T) { var v []uint8 = nil - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1385,7 +1385,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { t.Run("*[]uint8 non-nil", func(t *testing.T) { s := []uint8{1, 2, 3} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 3 * szUint8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1393,7 +1393,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { }) t.Run("*[]uint8 nil", func(t *testing.T) { var ps *[]uint8 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1402,7 +1402,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { t.Run("[]*uint8", func(t *testing.T) { a, b, c := uint8(1), uint8(2), uint8(3) v := []*uint8{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUint8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1411,7 +1411,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { t.Run("[]*uint8 with nil", func(t *testing.T) { a, b := uint8(1), uint8(2) v := []*uint8{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szUint8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1419,7 +1419,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { }) t.Run("[]*uint8 all nil", func(t *testing.T) { v := []*uint8{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1429,7 +1429,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { a, b := uint8(1), uint8(2) s := []*uint8{&a, nil, &b} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szUint8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1437,7 +1437,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { }) t.Run("*[]*uint8 nil", func(t *testing.T) { var ps *[]*uint8 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1445,7 +1445,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { }) t.Run("[3]uint8", func(t *testing.T) { v := [3]uint8{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUint8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1454,7 +1454,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { t.Run("*[3]uint8 non-nil", func(t *testing.T) { v := [3]uint8{1, 2, 3} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 3 * szUint8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1462,7 +1462,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { }) t.Run("*[3]uint8 nil", func(t *testing.T) { var pv *[3]uint8 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1471,7 +1471,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { t.Run("[3]*uint8", func(t *testing.T) { a, b, c := uint8(1), uint8(2), uint8(3) v := [3]*uint8{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUint8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1480,7 +1480,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { t.Run("[3]*uint8 with nil", func(t *testing.T) { a, b := uint8(1), uint8(2) v := [3]*uint8{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szUint8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1488,7 +1488,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { }) t.Run("[3]*uint8 all nil", func(t *testing.T) { v := [3]*uint8{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1498,7 +1498,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { a, b := uint8(1), uint8(2) v := [3]*uint8{&a, nil, &b} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 2 * szUint8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1506,7 +1506,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { }) t.Run("*[3]*uint8 nil", func(t *testing.T) { var pv *[3]*uint8 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1514,7 +1514,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { }) t.Run("[100]uint8", func(t *testing.T) { var v [100]uint8 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 100 * szUint8 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1522,7 +1522,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { }) t.Run("*[100]uint8 nil", func(t *testing.T) { var pv *[100]uint8 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1530,7 +1530,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { }) t.Run("[100]*uint8 all nil", func(t *testing.T) { var v [100]*uint8 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1538,7 +1538,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { }) t.Run("*[100]*uint8 nil", func(t *testing.T) { var pv *[100]*uint8 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1549,7 +1549,7 @@ func TestEstimatePayloadOf_uint8(t *testing.T) { func TestEstimatePayloadOf_uint16(t *testing.T) { t.Run("uint16", func(t *testing.T) { v := uint16(42) - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := szUint16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1558,7 +1558,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { t.Run("*uint16 non-nil", func(t *testing.T) { v := uint16(42) pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := szUint16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1566,7 +1566,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { }) t.Run("*uint16 nil", func(t *testing.T) { var pv *uint16 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1574,7 +1574,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { }) t.Run("[]uint16", func(t *testing.T) { v := []uint16{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUint16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1582,7 +1582,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { }) t.Run("[]uint16 empty", func(t *testing.T) { v := []uint16{} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1590,7 +1590,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { }) t.Run("[]uint16 nil", func(t *testing.T) { var v []uint16 = nil - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1599,7 +1599,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { t.Run("*[]uint16 non-nil", func(t *testing.T) { s := []uint16{1, 2, 3} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 3 * szUint16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1607,7 +1607,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { }) t.Run("*[]uint16 nil", func(t *testing.T) { var ps *[]uint16 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1616,7 +1616,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { t.Run("[]*uint16", func(t *testing.T) { a, b, c := uint16(1), uint16(2), uint16(3) v := []*uint16{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUint16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1625,7 +1625,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { t.Run("[]*uint16 with nil", func(t *testing.T) { a, b := uint16(1), uint16(2) v := []*uint16{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szUint16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1633,7 +1633,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { }) t.Run("[]*uint16 all nil", func(t *testing.T) { v := []*uint16{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1643,7 +1643,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { a, b := uint16(1), uint16(2) s := []*uint16{&a, nil, &b} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szUint16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1651,7 +1651,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { }) t.Run("*[]*uint16 nil", func(t *testing.T) { var ps *[]*uint16 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1659,7 +1659,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { }) t.Run("[3]uint16", func(t *testing.T) { v := [3]uint16{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUint16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1668,7 +1668,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { t.Run("*[3]uint16 non-nil", func(t *testing.T) { v := [3]uint16{1, 2, 3} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 3 * szUint16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1676,7 +1676,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { }) t.Run("*[3]uint16 nil", func(t *testing.T) { var pv *[3]uint16 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1685,7 +1685,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { t.Run("[3]*uint16", func(t *testing.T) { a, b, c := uint16(1), uint16(2), uint16(3) v := [3]*uint16{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUint16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1694,7 +1694,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { t.Run("[3]*uint16 with nil", func(t *testing.T) { a, b := uint16(1), uint16(2) v := [3]*uint16{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szUint16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1702,7 +1702,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { }) t.Run("[3]*uint16 all nil", func(t *testing.T) { v := [3]*uint16{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1712,7 +1712,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { a, b := uint16(1), uint16(2) v := [3]*uint16{&a, nil, &b} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 2 * szUint16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1720,7 +1720,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { }) t.Run("*[3]*uint16 nil", func(t *testing.T) { var pv *[3]*uint16 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1728,7 +1728,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { }) t.Run("[100]uint16", func(t *testing.T) { var v [100]uint16 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 100 * szUint16 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1736,7 +1736,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { }) t.Run("*[100]uint16 nil", func(t *testing.T) { var pv *[100]uint16 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1744,7 +1744,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { }) t.Run("[100]*uint16 all nil", func(t *testing.T) { var v [100]*uint16 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1752,7 +1752,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { }) t.Run("*[100]*uint16 nil", func(t *testing.T) { var pv *[100]*uint16 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1763,7 +1763,7 @@ func TestEstimatePayloadOf_uint16(t *testing.T) { func TestEstimatePayloadOf_uint32(t *testing.T) { t.Run("uint32", func(t *testing.T) { v := uint32(42) - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := szUint32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1772,7 +1772,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { t.Run("*uint32 non-nil", func(t *testing.T) { v := uint32(42) pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := szUint32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1780,7 +1780,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { }) t.Run("*uint32 nil", func(t *testing.T) { var pv *uint32 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1788,7 +1788,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { }) t.Run("[]uint32", func(t *testing.T) { v := []uint32{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUint32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1796,7 +1796,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { }) t.Run("[]uint32 empty", func(t *testing.T) { v := []uint32{} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1804,7 +1804,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { }) t.Run("[]uint32 nil", func(t *testing.T) { var v []uint32 = nil - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1813,7 +1813,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { t.Run("*[]uint32 non-nil", func(t *testing.T) { s := []uint32{1, 2, 3} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 3 * szUint32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1821,7 +1821,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { }) t.Run("*[]uint32 nil", func(t *testing.T) { var ps *[]uint32 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1830,7 +1830,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { t.Run("[]*uint32", func(t *testing.T) { a, b, c := uint32(1), uint32(2), uint32(3) v := []*uint32{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUint32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1839,7 +1839,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { t.Run("[]*uint32 with nil", func(t *testing.T) { a, b := uint32(1), uint32(2) v := []*uint32{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szUint32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1847,7 +1847,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { }) t.Run("[]*uint32 all nil", func(t *testing.T) { v := []*uint32{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1857,7 +1857,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { a, b := uint32(1), uint32(2) s := []*uint32{&a, nil, &b} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szUint32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1865,7 +1865,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { }) t.Run("*[]*uint32 nil", func(t *testing.T) { var ps *[]*uint32 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1873,7 +1873,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { }) t.Run("[3]uint32", func(t *testing.T) { v := [3]uint32{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUint32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1882,7 +1882,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { t.Run("*[3]uint32 non-nil", func(t *testing.T) { v := [3]uint32{1, 2, 3} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 3 * szUint32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1890,7 +1890,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { }) t.Run("*[3]uint32 nil", func(t *testing.T) { var pv *[3]uint32 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1899,7 +1899,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { t.Run("[3]*uint32", func(t *testing.T) { a, b, c := uint32(1), uint32(2), uint32(3) v := [3]*uint32{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUint32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1908,7 +1908,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { t.Run("[3]*uint32 with nil", func(t *testing.T) { a, b := uint32(1), uint32(2) v := [3]*uint32{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szUint32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1916,7 +1916,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { }) t.Run("[3]*uint32 all nil", func(t *testing.T) { v := [3]*uint32{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1926,7 +1926,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { a, b := uint32(1), uint32(2) v := [3]*uint32{&a, nil, &b} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 2 * szUint32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1934,7 +1934,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { }) t.Run("*[3]*uint32 nil", func(t *testing.T) { var pv *[3]*uint32 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1942,7 +1942,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { }) t.Run("[100]uint32", func(t *testing.T) { var v [100]uint32 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 100 * szUint32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1950,7 +1950,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { }) t.Run("*[100]uint32 nil", func(t *testing.T) { var pv *[100]uint32 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1958,7 +1958,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { }) t.Run("[100]*uint32 all nil", func(t *testing.T) { var v [100]*uint32 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1966,7 +1966,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { }) t.Run("*[100]*uint32 nil", func(t *testing.T) { var pv *[100]*uint32 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1977,7 +1977,7 @@ func TestEstimatePayloadOf_uint32(t *testing.T) { func TestEstimatePayloadOf_uint64(t *testing.T) { t.Run("uint64", func(t *testing.T) { v := uint64(42) - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := szUint64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1986,7 +1986,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { t.Run("*uint64 non-nil", func(t *testing.T) { v := uint64(42) pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := szUint64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -1994,7 +1994,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { }) t.Run("*uint64 nil", func(t *testing.T) { var pv *uint64 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2002,7 +2002,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { }) t.Run("[]uint64", func(t *testing.T) { v := []uint64{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUint64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2010,7 +2010,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { }) t.Run("[]uint64 empty", func(t *testing.T) { v := []uint64{} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2018,7 +2018,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { }) t.Run("[]uint64 nil", func(t *testing.T) { var v []uint64 = nil - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2027,7 +2027,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { t.Run("*[]uint64 non-nil", func(t *testing.T) { s := []uint64{1, 2, 3} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 3 * szUint64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2035,7 +2035,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { }) t.Run("*[]uint64 nil", func(t *testing.T) { var ps *[]uint64 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2044,7 +2044,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { t.Run("[]*uint64", func(t *testing.T) { a, b, c := uint64(1), uint64(2), uint64(3) v := []*uint64{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUint64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2053,7 +2053,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { t.Run("[]*uint64 with nil", func(t *testing.T) { a, b := uint64(1), uint64(2) v := []*uint64{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szUint64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2061,7 +2061,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { }) t.Run("[]*uint64 all nil", func(t *testing.T) { v := []*uint64{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2071,7 +2071,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { a, b := uint64(1), uint64(2) s := []*uint64{&a, nil, &b} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szUint64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2079,7 +2079,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { }) t.Run("*[]*uint64 nil", func(t *testing.T) { var ps *[]*uint64 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2087,7 +2087,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { }) t.Run("[3]uint64", func(t *testing.T) { v := [3]uint64{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUint64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2096,7 +2096,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { t.Run("*[3]uint64 non-nil", func(t *testing.T) { v := [3]uint64{1, 2, 3} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 3 * szUint64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2104,7 +2104,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { }) t.Run("*[3]uint64 nil", func(t *testing.T) { var pv *[3]uint64 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2113,7 +2113,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { t.Run("[3]*uint64", func(t *testing.T) { a, b, c := uint64(1), uint64(2), uint64(3) v := [3]*uint64{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUint64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2122,7 +2122,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { t.Run("[3]*uint64 with nil", func(t *testing.T) { a, b := uint64(1), uint64(2) v := [3]*uint64{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szUint64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2130,7 +2130,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { }) t.Run("[3]*uint64 all nil", func(t *testing.T) { v := [3]*uint64{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2140,7 +2140,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { a, b := uint64(1), uint64(2) v := [3]*uint64{&a, nil, &b} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 2 * szUint64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2148,7 +2148,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { }) t.Run("*[3]*uint64 nil", func(t *testing.T) { var pv *[3]*uint64 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2156,7 +2156,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { }) t.Run("[100]uint64", func(t *testing.T) { var v [100]uint64 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 100 * szUint64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2164,7 +2164,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { }) t.Run("*[100]uint64 nil", func(t *testing.T) { var pv *[100]uint64 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2172,7 +2172,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { }) t.Run("[100]*uint64 all nil", func(t *testing.T) { var v [100]*uint64 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2180,7 +2180,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { }) t.Run("*[100]*uint64 nil", func(t *testing.T) { var pv *[100]*uint64 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2191,7 +2191,7 @@ func TestEstimatePayloadOf_uint64(t *testing.T) { func TestEstimatePayloadOf_uintptr(t *testing.T) { t.Run("uintptr", func(t *testing.T) { v := uintptr(42) - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := szUintptr if got != want { t.Errorf("got %d, want %d", got, want) @@ -2200,7 +2200,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { t.Run("*uintptr non-nil", func(t *testing.T) { v := uintptr(42) pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := szUintptr if got != want { t.Errorf("got %d, want %d", got, want) @@ -2208,7 +2208,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { }) t.Run("*uintptr nil", func(t *testing.T) { var pv *uintptr = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2216,7 +2216,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { }) t.Run("[]uintptr", func(t *testing.T) { v := []uintptr{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUintptr if got != want { t.Errorf("got %d, want %d", got, want) @@ -2224,7 +2224,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { }) t.Run("[]uintptr empty", func(t *testing.T) { v := []uintptr{} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2232,7 +2232,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { }) t.Run("[]uintptr nil", func(t *testing.T) { var v []uintptr = nil - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2241,7 +2241,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { t.Run("*[]uintptr non-nil", func(t *testing.T) { s := []uintptr{1, 2, 3} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 3 * szUintptr if got != want { t.Errorf("got %d, want %d", got, want) @@ -2249,7 +2249,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { }) t.Run("*[]uintptr nil", func(t *testing.T) { var ps *[]uintptr = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2258,7 +2258,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { t.Run("[]*uintptr", func(t *testing.T) { a, b, c := uintptr(1), uintptr(2), uintptr(3) v := []*uintptr{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUintptr if got != want { t.Errorf("got %d, want %d", got, want) @@ -2267,7 +2267,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { t.Run("[]*uintptr with nil", func(t *testing.T) { a, b := uintptr(1), uintptr(2) v := []*uintptr{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szUintptr if got != want { t.Errorf("got %d, want %d", got, want) @@ -2275,7 +2275,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { }) t.Run("[]*uintptr all nil", func(t *testing.T) { v := []*uintptr{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2285,7 +2285,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { a, b := uintptr(1), uintptr(2) s := []*uintptr{&a, nil, &b} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szUintptr if got != want { t.Errorf("got %d, want %d", got, want) @@ -2293,7 +2293,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { }) t.Run("*[]*uintptr nil", func(t *testing.T) { var ps *[]*uintptr = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2301,7 +2301,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { }) t.Run("[3]uintptr", func(t *testing.T) { v := [3]uintptr{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUintptr if got != want { t.Errorf("got %d, want %d", got, want) @@ -2310,7 +2310,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { t.Run("*[3]uintptr non-nil", func(t *testing.T) { v := [3]uintptr{1, 2, 3} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 3 * szUintptr if got != want { t.Errorf("got %d, want %d", got, want) @@ -2318,7 +2318,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { }) t.Run("*[3]uintptr nil", func(t *testing.T) { var pv *[3]uintptr = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2327,7 +2327,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { t.Run("[3]*uintptr", func(t *testing.T) { a, b, c := uintptr(1), uintptr(2), uintptr(3) v := [3]*uintptr{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szUintptr if got != want { t.Errorf("got %d, want %d", got, want) @@ -2336,7 +2336,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { t.Run("[3]*uintptr with nil", func(t *testing.T) { a, b := uintptr(1), uintptr(2) v := [3]*uintptr{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szUintptr if got != want { t.Errorf("got %d, want %d", got, want) @@ -2344,7 +2344,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { }) t.Run("[3]*uintptr all nil", func(t *testing.T) { v := [3]*uintptr{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2354,7 +2354,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { a, b := uintptr(1), uintptr(2) v := [3]*uintptr{&a, nil, &b} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 2 * szUintptr if got != want { t.Errorf("got %d, want %d", got, want) @@ -2362,7 +2362,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { }) t.Run("*[3]*uintptr nil", func(t *testing.T) { var pv *[3]*uintptr = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2370,7 +2370,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { }) t.Run("[100]uintptr", func(t *testing.T) { var v [100]uintptr - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 100 * szUintptr if got != want { t.Errorf("got %d, want %d", got, want) @@ -2378,7 +2378,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { }) t.Run("*[100]uintptr nil", func(t *testing.T) { var pv *[100]uintptr = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2386,7 +2386,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { }) t.Run("[100]*uintptr all nil", func(t *testing.T) { var v [100]*uintptr - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2394,7 +2394,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { }) t.Run("*[100]*uintptr nil", func(t *testing.T) { var pv *[100]*uintptr = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2405,7 +2405,7 @@ func TestEstimatePayloadOf_uintptr(t *testing.T) { func TestEstimatePayloadOf_float32(t *testing.T) { t.Run("float32", func(t *testing.T) { v := float32(42.0) - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := szFloat32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2414,7 +2414,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { t.Run("*float32 non-nil", func(t *testing.T) { v := float32(42.0) pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := szFloat32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2422,7 +2422,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { }) t.Run("*float32 nil", func(t *testing.T) { var pv *float32 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2430,7 +2430,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { }) t.Run("[]float32", func(t *testing.T) { v := []float32{1.0, 2.0, 3.0} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szFloat32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2438,7 +2438,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { }) t.Run("[]float32 empty", func(t *testing.T) { v := []float32{} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2446,7 +2446,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { }) t.Run("[]float32 nil", func(t *testing.T) { var v []float32 = nil - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2455,7 +2455,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { t.Run("*[]float32 non-nil", func(t *testing.T) { s := []float32{1.0, 2.0, 3.0} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 3 * szFloat32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2463,7 +2463,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { }) t.Run("*[]float32 nil", func(t *testing.T) { var ps *[]float32 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2472,7 +2472,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { t.Run("[]*float32", func(t *testing.T) { a, b, c := float32(1.0), float32(2.0), float32(3.0) v := []*float32{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szFloat32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2481,7 +2481,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { t.Run("[]*float32 with nil", func(t *testing.T) { a, b := float32(1.0), float32(2.0) v := []*float32{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szFloat32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2489,7 +2489,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { }) t.Run("[]*float32 all nil", func(t *testing.T) { v := []*float32{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2499,7 +2499,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { a, b := float32(1.0), float32(2.0) s := []*float32{&a, nil, &b} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szFloat32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2507,7 +2507,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { }) t.Run("*[]*float32 nil", func(t *testing.T) { var ps *[]*float32 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2515,7 +2515,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { }) t.Run("[3]float32", func(t *testing.T) { v := [3]float32{1.0, 2.0, 3.0} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szFloat32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2524,7 +2524,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { t.Run("*[3]float32 non-nil", func(t *testing.T) { v := [3]float32{1.0, 2.0, 3.0} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 3 * szFloat32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2532,7 +2532,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { }) t.Run("*[3]float32 nil", func(t *testing.T) { var pv *[3]float32 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2541,7 +2541,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { t.Run("[3]*float32", func(t *testing.T) { a, b, c := float32(1.0), float32(2.0), float32(3.0) v := [3]*float32{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szFloat32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2550,7 +2550,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { t.Run("[3]*float32 with nil", func(t *testing.T) { a, b := float32(1.0), float32(2.0) v := [3]*float32{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szFloat32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2558,7 +2558,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { }) t.Run("[3]*float32 all nil", func(t *testing.T) { v := [3]*float32{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2568,7 +2568,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { a, b := float32(1.0), float32(2.0) v := [3]*float32{&a, nil, &b} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 2 * szFloat32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2576,7 +2576,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { }) t.Run("*[3]*float32 nil", func(t *testing.T) { var pv *[3]*float32 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2584,7 +2584,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { }) t.Run("[100]float32", func(t *testing.T) { var v [100]float32 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 100 * szFloat32 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2592,7 +2592,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { }) t.Run("*[100]float32 nil", func(t *testing.T) { var pv *[100]float32 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2600,7 +2600,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { }) t.Run("[100]*float32 all nil", func(t *testing.T) { var v [100]*float32 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2608,7 +2608,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { }) t.Run("*[100]*float32 nil", func(t *testing.T) { var pv *[100]*float32 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2619,7 +2619,7 @@ func TestEstimatePayloadOf_float32(t *testing.T) { func TestEstimatePayloadOf_float64(t *testing.T) { t.Run("float64", func(t *testing.T) { v := float64(42.0) - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := szFloat64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2628,7 +2628,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { t.Run("*float64 non-nil", func(t *testing.T) { v := float64(42.0) pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := szFloat64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2636,7 +2636,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { }) t.Run("*float64 nil", func(t *testing.T) { var pv *float64 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2644,7 +2644,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { }) t.Run("[]float64", func(t *testing.T) { v := []float64{1.0, 2.0, 3.0} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szFloat64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2652,7 +2652,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { }) t.Run("[]float64 empty", func(t *testing.T) { v := []float64{} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2660,7 +2660,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { }) t.Run("[]float64 nil", func(t *testing.T) { var v []float64 = nil - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2669,7 +2669,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { t.Run("*[]float64 non-nil", func(t *testing.T) { s := []float64{1.0, 2.0, 3.0} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 3 * szFloat64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2677,7 +2677,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { }) t.Run("*[]float64 nil", func(t *testing.T) { var ps *[]float64 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2686,7 +2686,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { t.Run("[]*float64", func(t *testing.T) { a, b, c := float64(1.0), float64(2.0), float64(3.0) v := []*float64{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szFloat64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2695,7 +2695,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { t.Run("[]*float64 with nil", func(t *testing.T) { a, b := float64(1.0), float64(2.0) v := []*float64{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szFloat64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2703,7 +2703,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { }) t.Run("[]*float64 all nil", func(t *testing.T) { v := []*float64{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2713,7 +2713,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { a, b := float64(1.0), float64(2.0) s := []*float64{&a, nil, &b} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szFloat64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2721,7 +2721,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { }) t.Run("*[]*float64 nil", func(t *testing.T) { var ps *[]*float64 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2729,7 +2729,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { }) t.Run("[3]float64", func(t *testing.T) { v := [3]float64{1.0, 2.0, 3.0} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szFloat64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2738,7 +2738,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { t.Run("*[3]float64 non-nil", func(t *testing.T) { v := [3]float64{1.0, 2.0, 3.0} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 3 * szFloat64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2746,7 +2746,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { }) t.Run("*[3]float64 nil", func(t *testing.T) { var pv *[3]float64 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2755,7 +2755,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { t.Run("[3]*float64", func(t *testing.T) { a, b, c := float64(1.0), float64(2.0), float64(3.0) v := [3]*float64{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szFloat64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2764,7 +2764,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { t.Run("[3]*float64 with nil", func(t *testing.T) { a, b := float64(1.0), float64(2.0) v := [3]*float64{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szFloat64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2772,7 +2772,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { }) t.Run("[3]*float64 all nil", func(t *testing.T) { v := [3]*float64{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2782,7 +2782,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { a, b := float64(1.0), float64(2.0) v := [3]*float64{&a, nil, &b} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 2 * szFloat64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2790,7 +2790,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { }) t.Run("*[3]*float64 nil", func(t *testing.T) { var pv *[3]*float64 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2798,7 +2798,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { }) t.Run("[100]float64", func(t *testing.T) { var v [100]float64 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 100 * szFloat64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2806,7 +2806,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { }) t.Run("*[100]float64 nil", func(t *testing.T) { var pv *[100]float64 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2814,7 +2814,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { }) t.Run("[100]*float64 all nil", func(t *testing.T) { var v [100]*float64 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2822,7 +2822,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { }) t.Run("*[100]*float64 nil", func(t *testing.T) { var pv *[100]*float64 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2833,7 +2833,7 @@ func TestEstimatePayloadOf_float64(t *testing.T) { func TestEstimatePayloadOf_complex64(t *testing.T) { t.Run("complex64", func(t *testing.T) { v := complex64(42) - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := szComplex64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2842,7 +2842,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { t.Run("*complex64 non-nil", func(t *testing.T) { v := complex64(42) pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := szComplex64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2850,7 +2850,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { }) t.Run("*complex64 nil", func(t *testing.T) { var pv *complex64 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2858,7 +2858,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { }) t.Run("[]complex64", func(t *testing.T) { v := []complex64{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szComplex64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2866,7 +2866,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { }) t.Run("[]complex64 empty", func(t *testing.T) { v := []complex64{} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2874,7 +2874,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { }) t.Run("[]complex64 nil", func(t *testing.T) { var v []complex64 = nil - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2883,7 +2883,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { t.Run("*[]complex64 non-nil", func(t *testing.T) { s := []complex64{1, 2, 3} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 3 * szComplex64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2891,7 +2891,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { }) t.Run("*[]complex64 nil", func(t *testing.T) { var ps *[]complex64 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2900,7 +2900,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { t.Run("[]*complex64", func(t *testing.T) { a, b, c := complex64(1), complex64(2), complex64(3) v := []*complex64{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szComplex64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2909,7 +2909,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { t.Run("[]*complex64 with nil", func(t *testing.T) { a, b := complex64(1), complex64(2) v := []*complex64{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szComplex64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2917,7 +2917,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { }) t.Run("[]*complex64 all nil", func(t *testing.T) { v := []*complex64{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2927,7 +2927,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { a, b := complex64(1), complex64(2) s := []*complex64{&a, nil, &b} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szComplex64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2935,7 +2935,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { }) t.Run("*[]*complex64 nil", func(t *testing.T) { var ps *[]*complex64 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2943,7 +2943,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { }) t.Run("[3]complex64", func(t *testing.T) { v := [3]complex64{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szComplex64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2952,7 +2952,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { t.Run("*[3]complex64 non-nil", func(t *testing.T) { v := [3]complex64{1, 2, 3} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 3 * szComplex64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2960,7 +2960,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { }) t.Run("*[3]complex64 nil", func(t *testing.T) { var pv *[3]complex64 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2969,7 +2969,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { t.Run("[3]*complex64", func(t *testing.T) { a, b, c := complex64(1), complex64(2), complex64(3) v := [3]*complex64{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szComplex64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2978,7 +2978,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { t.Run("[3]*complex64 with nil", func(t *testing.T) { a, b := complex64(1), complex64(2) v := [3]*complex64{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szComplex64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2986,7 +2986,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { }) t.Run("[3]*complex64 all nil", func(t *testing.T) { v := [3]*complex64{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -2996,7 +2996,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { a, b := complex64(1), complex64(2) v := [3]*complex64{&a, nil, &b} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 2 * szComplex64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3004,7 +3004,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { }) t.Run("*[3]*complex64 nil", func(t *testing.T) { var pv *[3]*complex64 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3012,7 +3012,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { }) t.Run("[100]complex64", func(t *testing.T) { var v [100]complex64 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 100 * szComplex64 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3020,7 +3020,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { }) t.Run("*[100]complex64 nil", func(t *testing.T) { var pv *[100]complex64 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3028,7 +3028,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { }) t.Run("[100]*complex64 all nil", func(t *testing.T) { var v [100]*complex64 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3036,7 +3036,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { }) t.Run("*[100]*complex64 nil", func(t *testing.T) { var pv *[100]*complex64 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3047,7 +3047,7 @@ func TestEstimatePayloadOf_complex64(t *testing.T) { func TestEstimatePayloadOf_complex128(t *testing.T) { t.Run("complex128", func(t *testing.T) { v := complex128(42) - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := szComplex128 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3056,7 +3056,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { t.Run("*complex128 non-nil", func(t *testing.T) { v := complex128(42) pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := szComplex128 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3064,7 +3064,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { }) t.Run("*complex128 nil", func(t *testing.T) { var pv *complex128 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3072,7 +3072,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { }) t.Run("[]complex128", func(t *testing.T) { v := []complex128{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szComplex128 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3080,7 +3080,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { }) t.Run("[]complex128 empty", func(t *testing.T) { v := []complex128{} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3088,7 +3088,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { }) t.Run("[]complex128 nil", func(t *testing.T) { var v []complex128 = nil - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3097,7 +3097,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { t.Run("*[]complex128 non-nil", func(t *testing.T) { s := []complex128{1, 2, 3} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 3 * szComplex128 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3105,7 +3105,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { }) t.Run("*[]complex128 nil", func(t *testing.T) { var ps *[]complex128 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3114,7 +3114,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { t.Run("[]*complex128", func(t *testing.T) { a, b, c := complex128(1), complex128(2), complex128(3) v := []*complex128{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szComplex128 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3123,7 +3123,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { t.Run("[]*complex128 with nil", func(t *testing.T) { a, b := complex128(1), complex128(2) v := []*complex128{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szComplex128 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3131,7 +3131,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { }) t.Run("[]*complex128 all nil", func(t *testing.T) { v := []*complex128{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3141,7 +3141,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { a, b := complex128(1), complex128(2) s := []*complex128{&a, nil, &b} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szComplex128 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3149,7 +3149,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { }) t.Run("*[]*complex128 nil", func(t *testing.T) { var ps *[]*complex128 = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3157,7 +3157,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { }) t.Run("[3]complex128", func(t *testing.T) { v := [3]complex128{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szComplex128 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3166,7 +3166,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { t.Run("*[3]complex128 non-nil", func(t *testing.T) { v := [3]complex128{1, 2, 3} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 3 * szComplex128 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3174,7 +3174,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { }) t.Run("*[3]complex128 nil", func(t *testing.T) { var pv *[3]complex128 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3183,7 +3183,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { t.Run("[3]*complex128", func(t *testing.T) { a, b, c := complex128(1), complex128(2), complex128(3) v := [3]*complex128{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szComplex128 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3192,7 +3192,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { t.Run("[3]*complex128 with nil", func(t *testing.T) { a, b := complex128(1), complex128(2) v := [3]*complex128{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szComplex128 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3200,7 +3200,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { }) t.Run("[3]*complex128 all nil", func(t *testing.T) { v := [3]*complex128{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3210,7 +3210,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { a, b := complex128(1), complex128(2) v := [3]*complex128{&a, nil, &b} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 2 * szComplex128 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3218,7 +3218,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { }) t.Run("*[3]*complex128 nil", func(t *testing.T) { var pv *[3]*complex128 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3226,7 +3226,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { }) t.Run("[100]complex128", func(t *testing.T) { var v [100]complex128 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 100 * szComplex128 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3234,7 +3234,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { }) t.Run("*[100]complex128 nil", func(t *testing.T) { var pv *[100]complex128 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3242,7 +3242,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { }) t.Run("[100]*complex128 all nil", func(t *testing.T) { var v [100]*complex128 - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3250,7 +3250,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { }) t.Run("*[100]*complex128 nil", func(t *testing.T) { var pv *[100]*complex128 = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3261,7 +3261,7 @@ func TestEstimatePayloadOf_complex128(t *testing.T) { func TestEstimatePayloadOf_bool(t *testing.T) { t.Run("bool", func(t *testing.T) { v := true - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := szBool if got != want { t.Errorf("got %d, want %d", got, want) @@ -3270,7 +3270,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { t.Run("*bool non-nil", func(t *testing.T) { v := true pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := szBool if got != want { t.Errorf("got %d, want %d", got, want) @@ -3278,7 +3278,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { }) t.Run("*bool nil", func(t *testing.T) { var pv *bool = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3286,7 +3286,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { }) t.Run("[]bool", func(t *testing.T) { v := []bool{true, false, true} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szBool if got != want { t.Errorf("got %d, want %d", got, want) @@ -3294,7 +3294,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { }) t.Run("[]bool empty", func(t *testing.T) { v := []bool{} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3302,7 +3302,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { }) t.Run("[]bool nil", func(t *testing.T) { var v []bool = nil - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3311,7 +3311,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { t.Run("*[]bool non-nil", func(t *testing.T) { s := []bool{true, false} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szBool if got != want { t.Errorf("got %d, want %d", got, want) @@ -3319,7 +3319,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { }) t.Run("*[]bool nil", func(t *testing.T) { var ps *[]bool = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3328,7 +3328,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { t.Run("[]*bool", func(t *testing.T) { a, b, c := true, false, true v := []*bool{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szBool if got != want { t.Errorf("got %d, want %d", got, want) @@ -3337,7 +3337,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { t.Run("[]*bool with nil", func(t *testing.T) { a, b := true, false v := []*bool{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szBool if got != want { t.Errorf("got %d, want %d", got, want) @@ -3345,7 +3345,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { }) t.Run("[]*bool all nil", func(t *testing.T) { v := []*bool{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3355,7 +3355,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { a, b := true, false s := []*bool{&a, nil, &b} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szBool if got != want { t.Errorf("got %d, want %d", got, want) @@ -3363,7 +3363,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { }) t.Run("*[]*bool nil", func(t *testing.T) { var ps *[]*bool = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3371,7 +3371,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { }) t.Run("[3]bool", func(t *testing.T) { v := [3]bool{true, false, true} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szBool if got != want { t.Errorf("got %d, want %d", got, want) @@ -3380,7 +3380,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { t.Run("*[3]bool non-nil", func(t *testing.T) { v := [3]bool{true, false, true} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 3 * szBool if got != want { t.Errorf("got %d, want %d", got, want) @@ -3388,7 +3388,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { }) t.Run("*[3]bool nil", func(t *testing.T) { var pv *[3]bool = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3397,7 +3397,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { t.Run("[3]*bool", func(t *testing.T) { a, b, c := true, false, true v := [3]*bool{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szBool if got != want { t.Errorf("got %d, want %d", got, want) @@ -3406,7 +3406,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { t.Run("[3]*bool with nil", func(t *testing.T) { a, b := true, false v := [3]*bool{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szBool if got != want { t.Errorf("got %d, want %d", got, want) @@ -3414,7 +3414,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { }) t.Run("[3]*bool all nil", func(t *testing.T) { v := [3]*bool{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3424,7 +3424,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { a, b := true, false v := [3]*bool{&a, nil, &b} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 2 * szBool if got != want { t.Errorf("got %d, want %d", got, want) @@ -3432,7 +3432,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { }) t.Run("*[3]*bool nil", func(t *testing.T) { var pv *[3]*bool = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3440,7 +3440,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { }) t.Run("[100]bool", func(t *testing.T) { var v [100]bool - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 100 * szBool if got != want { t.Errorf("got %d, want %d", got, want) @@ -3448,7 +3448,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { }) t.Run("*[100]bool nil", func(t *testing.T) { var pv *[100]bool = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3456,7 +3456,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { }) t.Run("[100]*bool all nil", func(t *testing.T) { var v [100]*bool - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3464,7 +3464,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { }) t.Run("*[100]*bool nil", func(t *testing.T) { var pv *[100]*bool = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3475,7 +3475,7 @@ func TestEstimatePayloadOf_bool(t *testing.T) { func TestEstimatePayloadOf_string(t *testing.T) { t.Run("string", func(t *testing.T) { v := "hello" - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 5 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3483,7 +3483,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { }) t.Run("string empty", func(t *testing.T) { v := "" - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3492,7 +3492,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { t.Run("*string non-nil", func(t *testing.T) { v := "hello" pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 5 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3500,7 +3500,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { }) t.Run("*string nil", func(t *testing.T) { var pv *string = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3508,7 +3508,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { }) t.Run("[]string", func(t *testing.T) { v := []string{"he", "llo", ""} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 + 3 + 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3516,7 +3516,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { }) t.Run("[]string empty", func(t *testing.T) { v := []string{} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3524,7 +3524,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { }) t.Run("[]string nil", func(t *testing.T) { var v []string = nil - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3533,7 +3533,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { t.Run("*[]string non-nil", func(t *testing.T) { s := []string{"he", "llo"} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 + 3 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3541,7 +3541,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { }) t.Run("*[]string nil", func(t *testing.T) { var ps *[]string = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3550,7 +3550,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { t.Run("[]*string", func(t *testing.T) { a, b, c := "he", "llo", "" v := []*string{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 + 3 + 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3559,7 +3559,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { t.Run("[]*string with nil", func(t *testing.T) { a, b := "he", "llo" v := []*string{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 + 3 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3567,7 +3567,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { }) t.Run("[]*string all nil", func(t *testing.T) { v := []*string{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3577,7 +3577,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { a, b := "he", "llo" s := []*string{&a, nil, &b} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 + 3 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3585,7 +3585,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { }) t.Run("*[]*string nil", func(t *testing.T) { var ps *[]*string = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3593,7 +3593,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { }) t.Run("[3]string", func(t *testing.T) { v := [3]string{"he", "llo", ""} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 + 3 + 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3602,7 +3602,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { t.Run("*[3]string non-nil", func(t *testing.T) { v := [3]string{"he", "llo", ""} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 2 + 3 + 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3610,7 +3610,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { }) t.Run("*[3]string nil", func(t *testing.T) { var pv *[3]string = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3619,7 +3619,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { t.Run("[3]*string", func(t *testing.T) { a, b, c := "he", "llo", "" v := [3]*string{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 + 3 + 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3628,7 +3628,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { t.Run("[3]*string with nil", func(t *testing.T) { a, b := "he", "llo" v := [3]*string{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 + 3 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3636,7 +3636,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { }) t.Run("[3]*string all nil", func(t *testing.T) { v := [3]*string{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3646,7 +3646,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { a, b := "he", "llo" v := [3]*string{&a, nil, &b} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 2 + 3 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3654,7 +3654,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { }) t.Run("*[3]*string nil", func(t *testing.T) { var pv *[3]*string = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3662,7 +3662,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { }) t.Run("[100]string", func(t *testing.T) { var v [100]string // all empty - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3670,7 +3670,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { }) t.Run("*[100]string nil", func(t *testing.T) { var pv *[100]string = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3678,7 +3678,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { }) t.Run("[100]*string all nil", func(t *testing.T) { var v [100]*string - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3686,7 +3686,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { }) t.Run("*[100]*string nil", func(t *testing.T) { var pv *[100]*string = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3697,7 +3697,7 @@ func TestEstimatePayloadOf_string(t *testing.T) { func TestEstimatePayloadOf_timeTime(t *testing.T) { t.Run("time.Time", func(t *testing.T) { v := time.Now() - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := szTime if got != want { t.Errorf("got %d, want %d", got, want) @@ -3706,7 +3706,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { t.Run("*time.Time non-nil", func(t *testing.T) { v := time.Now() pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := szTime if got != want { t.Errorf("got %d, want %d", got, want) @@ -3714,7 +3714,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { }) t.Run("*time.Time nil", func(t *testing.T) { var pv *time.Time = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3722,7 +3722,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { }) t.Run("[]time.Time", func(t *testing.T) { v := []time.Time{time.Now(), time.Now(), time.Now()} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szTime if got != want { t.Errorf("got %d, want %d", got, want) @@ -3730,7 +3730,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { }) t.Run("[]time.Time empty", func(t *testing.T) { v := []time.Time{} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3738,7 +3738,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { }) t.Run("[]time.Time nil", func(t *testing.T) { var v []time.Time = nil - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3747,7 +3747,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { t.Run("*[]time.Time non-nil", func(t *testing.T) { s := []time.Time{time.Now(), time.Now()} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szTime if got != want { t.Errorf("got %d, want %d", got, want) @@ -3755,7 +3755,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { }) t.Run("*[]time.Time nil", func(t *testing.T) { var ps *[]time.Time = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3766,7 +3766,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { b := time.Now() c := time.Now() v := []*time.Time{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szTime if got != want { t.Errorf("got %d, want %d", got, want) @@ -3775,7 +3775,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { t.Run("[]*time.Time with nil", func(t *testing.T) { a, b := time.Now(), time.Now() v := []*time.Time{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szTime if got != want { t.Errorf("got %d, want %d", got, want) @@ -3783,7 +3783,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { }) t.Run("[]*time.Time all nil", func(t *testing.T) { v := []*time.Time{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3793,7 +3793,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { a, b := time.Now(), time.Now() s := []*time.Time{&a, nil, &b} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szTime if got != want { t.Errorf("got %d, want %d", got, want) @@ -3801,7 +3801,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { }) t.Run("*[]*time.Time nil", func(t *testing.T) { var ps *[]*time.Time = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3809,7 +3809,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { }) t.Run("[3]time.Time", func(t *testing.T) { v := [3]time.Time{time.Now(), time.Now(), time.Now()} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szTime if got != want { t.Errorf("got %d, want %d", got, want) @@ -3818,7 +3818,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { t.Run("*[3]time.Time non-nil", func(t *testing.T) { v := [3]time.Time{time.Now(), time.Now(), time.Now()} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 3 * szTime if got != want { t.Errorf("got %d, want %d", got, want) @@ -3826,7 +3826,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { }) t.Run("*[3]time.Time nil", func(t *testing.T) { var pv *[3]time.Time = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3835,7 +3835,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { t.Run("[3]*time.Time", func(t *testing.T) { a, b, c := time.Now(), time.Now(), time.Now() v := [3]*time.Time{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szTime if got != want { t.Errorf("got %d, want %d", got, want) @@ -3844,7 +3844,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { t.Run("[3]*time.Time with nil", func(t *testing.T) { a, b := time.Now(), time.Now() v := [3]*time.Time{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szTime if got != want { t.Errorf("got %d, want %d", got, want) @@ -3852,7 +3852,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { }) t.Run("[3]*time.Time all nil", func(t *testing.T) { v := [3]*time.Time{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3862,7 +3862,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { a, b := time.Now(), time.Now() v := [3]*time.Time{&a, nil, &b} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 2 * szTime if got != want { t.Errorf("got %d, want %d", got, want) @@ -3870,7 +3870,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { }) t.Run("*[3]*time.Time nil", func(t *testing.T) { var pv *[3]*time.Time = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3878,7 +3878,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { }) t.Run("[100]time.Time", func(t *testing.T) { var v [100]time.Time - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 100 * szTime if got != want { t.Errorf("got %d, want %d", got, want) @@ -3886,7 +3886,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { }) t.Run("*[100]time.Time nil", func(t *testing.T) { var pv *[100]time.Time = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3894,7 +3894,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { }) t.Run("[100]*time.Time all nil", func(t *testing.T) { var v [100]*time.Time - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3902,7 +3902,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { }) t.Run("*[100]*time.Time nil", func(t *testing.T) { var pv *[100]*time.Time = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3913,7 +3913,7 @@ func TestEstimatePayloadOf_timeTime(t *testing.T) { func TestEstimatePayloadOf_timeDuration(t *testing.T) { t.Run("time.Duration", func(t *testing.T) { v := time.Duration(42) - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := szDuration if got != want { t.Errorf("got %d, want %d", got, want) @@ -3922,7 +3922,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { t.Run("*time.Duration non-nil", func(t *testing.T) { v := time.Duration(42) pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := szDuration if got != want { t.Errorf("got %d, want %d", got, want) @@ -3930,7 +3930,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { }) t.Run("*time.Duration nil", func(t *testing.T) { var pv *time.Duration = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3938,7 +3938,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { }) t.Run("[]time.Duration", func(t *testing.T) { v := []time.Duration{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szDuration if got != want { t.Errorf("got %d, want %d", got, want) @@ -3946,7 +3946,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { }) t.Run("[]time.Duration empty", func(t *testing.T) { v := []time.Duration{} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3954,7 +3954,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { }) t.Run("[]time.Duration nil", func(t *testing.T) { var v []time.Duration = nil - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3963,7 +3963,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { t.Run("*[]time.Duration non-nil", func(t *testing.T) { s := []time.Duration{1, 2} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szDuration if got != want { t.Errorf("got %d, want %d", got, want) @@ -3971,7 +3971,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { }) t.Run("*[]time.Duration nil", func(t *testing.T) { var ps *[]time.Duration = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -3980,7 +3980,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { t.Run("[]*time.Duration", func(t *testing.T) { a, b, c := time.Duration(1), time.Duration(2), time.Duration(3) v := []*time.Duration{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szDuration if got != want { t.Errorf("got %d, want %d", got, want) @@ -3989,7 +3989,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { t.Run("[]*time.Duration with nil", func(t *testing.T) { a, b := time.Duration(1), time.Duration(2) v := []*time.Duration{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szDuration if got != want { t.Errorf("got %d, want %d", got, want) @@ -3997,7 +3997,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { }) t.Run("[]*time.Duration all nil", func(t *testing.T) { v := []*time.Duration{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -4007,7 +4007,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { a, b := time.Duration(1), time.Duration(2) s := []*time.Duration{&a, nil, &b} ps := &s - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 2 * szDuration if got != want { t.Errorf("got %d, want %d", got, want) @@ -4015,7 +4015,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { }) t.Run("*[]*time.Duration nil", func(t *testing.T) { var ps *[]*time.Duration = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -4023,7 +4023,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { }) t.Run("[3]time.Duration", func(t *testing.T) { v := [3]time.Duration{1, 2, 3} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szDuration if got != want { t.Errorf("got %d, want %d", got, want) @@ -4032,7 +4032,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { t.Run("*[3]time.Duration non-nil", func(t *testing.T) { v := [3]time.Duration{1, 2, 3} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 3 * szDuration if got != want { t.Errorf("got %d, want %d", got, want) @@ -4040,7 +4040,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { }) t.Run("*[3]time.Duration nil", func(t *testing.T) { var pv *[3]time.Duration = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -4049,7 +4049,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { t.Run("[3]*time.Duration", func(t *testing.T) { a, b, c := time.Duration(1), time.Duration(2), time.Duration(3) v := [3]*time.Duration{&a, &b, &c} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 3 * szDuration if got != want { t.Errorf("got %d, want %d", got, want) @@ -4058,7 +4058,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { t.Run("[3]*time.Duration with nil", func(t *testing.T) { a, b := time.Duration(1), time.Duration(2) v := [3]*time.Duration{&a, nil, &b} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 2 * szDuration if got != want { t.Errorf("got %d, want %d", got, want) @@ -4066,7 +4066,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { }) t.Run("[3]*time.Duration all nil", func(t *testing.T) { v := [3]*time.Duration{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -4076,7 +4076,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { a, b := time.Duration(1), time.Duration(2) v := [3]*time.Duration{&a, nil, &b} pv := &v - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 2 * szDuration if got != want { t.Errorf("got %d, want %d", got, want) @@ -4084,7 +4084,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { }) t.Run("*[3]*time.Duration nil", func(t *testing.T) { var pv *[3]*time.Duration = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -4092,7 +4092,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { }) t.Run("[100]time.Duration", func(t *testing.T) { var v [100]time.Duration - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 100 * szDuration if got != want { t.Errorf("got %d, want %d", got, want) @@ -4100,7 +4100,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { }) t.Run("*[100]time.Duration nil", func(t *testing.T) { var pv *[100]time.Duration = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -4108,7 +4108,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { }) t.Run("[100]*time.Duration all nil", func(t *testing.T) { var v [100]*time.Duration - got := reflect.EstimatePayloadOf(v) + got := reflectx.EstimatePayloadOf(v) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -4116,7 +4116,7 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { }) t.Run("*[100]*time.Duration nil", func(t *testing.T) { var pv *[100]*time.Duration = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -4127,8 +4127,8 @@ func TestEstimatePayloadOf_timeDuration(t *testing.T) { func TestEstimatePayloadOf_CustomStruct(t *testing.T) { t.Run("CustomStruct", func(t *testing.T) { v := CustomStruct{} - got := reflect.EstimatePayloadOf(v) - want := reflect.ErrFailEstimatePayload + got := reflectx.EstimatePayloadOf(v) + want := reflectx.ErrFailEstimatePayload if got != want { t.Errorf("got %d, want %d", got, want) } @@ -4136,15 +4136,15 @@ func TestEstimatePayloadOf_CustomStruct(t *testing.T) { t.Run("*CustomStruct non-nil", func(t *testing.T) { v := CustomStruct{} pv := &v - got := reflect.EstimatePayloadOf(pv) - want := reflect.ErrFailEstimatePayload + got := reflectx.EstimatePayloadOf(pv) + want := reflectx.ErrFailEstimatePayload if got != want { t.Errorf("got %d, want %d", got, want) } }) t.Run("*CustomStruct nil", func(t *testing.T) { var pv *CustomStruct = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -4152,24 +4152,24 @@ func TestEstimatePayloadOf_CustomStruct(t *testing.T) { }) t.Run("[]CustomStruct", func(t *testing.T) { v := []CustomStruct{{}, {}} - got := reflect.EstimatePayloadOf(v) - want := reflect.ErrFailEstimatePayload + got := reflectx.EstimatePayloadOf(v) + want := reflectx.ErrFailEstimatePayload if got != want { t.Errorf("got %d, want %d", got, want) } }) t.Run("[]CustomStruct empty", func(t *testing.T) { v := []CustomStruct{} - got := reflect.EstimatePayloadOf(v) - want := reflect.ErrFailEstimatePayload + got := reflectx.EstimatePayloadOf(v) + want := reflectx.ErrFailEstimatePayload if got != want { t.Errorf("got %d, want %d", got, want) } }) t.Run("[]CustomStruct nil", func(t *testing.T) { var v []CustomStruct = nil - got := reflect.EstimatePayloadOf(v) - want := reflect.ErrFailEstimatePayload // because we the EstimatePayloadOf don't know about CustomStruct + got := reflectx.EstimatePayloadOf(v) + want := reflectx.ErrFailEstimatePayload // because we the EstimatePayloadOf don't know about CustomStruct if got != want { t.Errorf("got %d, want %d", got, want) } @@ -4177,15 +4177,15 @@ func TestEstimatePayloadOf_CustomStruct(t *testing.T) { t.Run("*[]CustomStruct non-nil", func(t *testing.T) { s := []CustomStruct{{}} ps := &s - got := reflect.EstimatePayloadOf(ps) - want := reflect.ErrFailEstimatePayload + got := reflectx.EstimatePayloadOf(ps) + want := reflectx.ErrFailEstimatePayload if got != want { t.Errorf("got %d, want %d", got, want) } }) t.Run("*[]CustomStruct nil", func(t *testing.T) { var ps *[]CustomStruct = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -4194,16 +4194,16 @@ func TestEstimatePayloadOf_CustomStruct(t *testing.T) { t.Run("[]*CustomStruct", func(t *testing.T) { a := CustomStruct{} v := []*CustomStruct{&a, nil} - got := reflect.EstimatePayloadOf(v) - want := reflect.ErrFailEstimatePayload + got := reflectx.EstimatePayloadOf(v) + want := reflectx.ErrFailEstimatePayload if got != want { t.Errorf("got %d, want %d", got, want) } }) t.Run("[]*CustomStruct all nil", func(t *testing.T) { v := []*CustomStruct{nil, nil} - got := reflect.EstimatePayloadOf(v) - want := reflect.ErrFailEstimatePayload // since fallback to payloadArray, and struct unknown, Err + got := reflectx.EstimatePayloadOf(v) + want := reflectx.ErrFailEstimatePayload // since fallback to payloadArray, and struct unknown, Err if got != want { t.Errorf("got %d, want %d", got, want) } @@ -4211,15 +4211,15 @@ func TestEstimatePayloadOf_CustomStruct(t *testing.T) { t.Run("*[]*CustomStruct non-nil", func(t *testing.T) { s := []*CustomStruct{nil} ps := &s - got := reflect.EstimatePayloadOf(ps) - want := reflect.ErrFailEstimatePayload + got := reflectx.EstimatePayloadOf(ps) + want := reflectx.ErrFailEstimatePayload if got != want { t.Errorf("got %d, want %d", got, want) } }) t.Run("*[]*CustomStruct nil", func(t *testing.T) { var ps *[]*CustomStruct = nil - got := reflect.EstimatePayloadOf(ps) + got := reflectx.EstimatePayloadOf(ps) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -4227,8 +4227,8 @@ func TestEstimatePayloadOf_CustomStruct(t *testing.T) { }) t.Run("[3]CustomStruct", func(t *testing.T) { v := [3]CustomStruct{{}, {}, {}} - got := reflect.EstimatePayloadOf(v) - want := reflect.ErrFailEstimatePayload + got := reflectx.EstimatePayloadOf(v) + want := reflectx.ErrFailEstimatePayload if got != want { t.Errorf("got %d, want %d", got, want) } @@ -4236,15 +4236,15 @@ func TestEstimatePayloadOf_CustomStruct(t *testing.T) { t.Run("*[3]CustomStruct non-nil", func(t *testing.T) { v := [3]CustomStruct{{}, {}, {}} pv := &v - got := reflect.EstimatePayloadOf(pv) - want := reflect.ErrFailEstimatePayload + got := reflectx.EstimatePayloadOf(pv) + want := reflectx.ErrFailEstimatePayload if got != want { t.Errorf("got %d, want %d", got, want) } }) t.Run("*[3]CustomStruct nil", func(t *testing.T) { var pv *[3]CustomStruct = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -4253,16 +4253,16 @@ func TestEstimatePayloadOf_CustomStruct(t *testing.T) { t.Run("[3]*CustomStruct", func(t *testing.T) { a := CustomStruct{} v := [3]*CustomStruct{&a, nil, &a} - got := reflect.EstimatePayloadOf(v) - want := reflect.ErrFailEstimatePayload + got := reflectx.EstimatePayloadOf(v) + want := reflectx.ErrFailEstimatePayload if got != want { t.Errorf("got %d, want %d", got, want) } }) t.Run("[3]*CustomStruct all nil", func(t *testing.T) { v := [3]*CustomStruct{nil, nil, nil} - got := reflect.EstimatePayloadOf(v) - want := reflect.ErrFailEstimatePayload // Err for unknown struct + got := reflectx.EstimatePayloadOf(v) + want := reflectx.ErrFailEstimatePayload // Err for unknown struct if got != want { t.Errorf("got %d, want %d", got, want) } @@ -4270,15 +4270,15 @@ func TestEstimatePayloadOf_CustomStruct(t *testing.T) { t.Run("*[3]*CustomStruct non-nil", func(t *testing.T) { v := [3]*CustomStruct{nil, nil, nil} pv := &v - got := reflect.EstimatePayloadOf(pv) - want := reflect.ErrFailEstimatePayload + got := reflectx.EstimatePayloadOf(pv) + want := reflectx.ErrFailEstimatePayload if got != want { t.Errorf("got %d, want %d", got, want) } }) t.Run("*[3]*CustomStruct nil", func(t *testing.T) { var pv *[3]*CustomStruct = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -4286,15 +4286,15 @@ func TestEstimatePayloadOf_CustomStruct(t *testing.T) { }) t.Run("[100]CustomStruct", func(t *testing.T) { var v [100]CustomStruct - got := reflect.EstimatePayloadOf(v) - want := reflect.ErrFailEstimatePayload + got := reflectx.EstimatePayloadOf(v) + want := reflectx.ErrFailEstimatePayload if got != want { t.Errorf("got %d, want %d", got, want) } }) t.Run("*[100]CustomStruct nil", func(t *testing.T) { var pv *[100]CustomStruct = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) @@ -4302,15 +4302,15 @@ func TestEstimatePayloadOf_CustomStruct(t *testing.T) { }) t.Run("[100]*CustomStruct all nil", func(t *testing.T) { var v [100]*CustomStruct - got := reflect.EstimatePayloadOf(v) - want := reflect.ErrFailEstimatePayload + got := reflectx.EstimatePayloadOf(v) + want := reflectx.ErrFailEstimatePayload if got != want { t.Errorf("got %d, want %d", got, want) } }) t.Run("*[100]*CustomStruct nil", func(t *testing.T) { var pv *[100]*CustomStruct = nil - got := reflect.EstimatePayloadOf(pv) + got := reflectx.EstimatePayloadOf(pv) want := 0 if got != want { t.Errorf("got %d, want %d", got, want) diff --git a/utils/structx/object_pool.go b/structx/object_pool.go similarity index 100% rename from utils/structx/object_pool.go rename to structx/object_pool.go diff --git a/utils/structx/object_pool_test.go b/structx/object_pool_test.go similarity index 95% rename from utils/structx/object_pool_test.go rename to structx/object_pool_test.go index 3c36779..751413c 100644 --- a/utils/structx/object_pool_test.go +++ b/structx/object_pool_test.go @@ -5,7 +5,7 @@ import ( "testing" "unsafe" - "github.com/lif0/pkg/utils/structx" + "github.com/lif0/pkg/structx" "github.com/stretchr/testify/assert" ) diff --git a/utils/structx/ordered_map.go b/structx/ordered_map.go similarity index 98% rename from utils/structx/ordered_map.go rename to structx/ordered_map.go index 1e02f1a..c984336 100644 --- a/utils/structx/ordered_map.go +++ b/structx/ordered_map.go @@ -1,7 +1,7 @@ package structx import ( - "github.com/lif0/pkg/utils/internal" + "github.com/lif0/pkg/internal" ) type kv[K any, V any] struct { diff --git a/utils/structx/ordered_map_bench_test.go b/structx/ordered_map_bench_test.go similarity index 99% rename from utils/structx/ordered_map_bench_test.go rename to structx/ordered_map_bench_test.go index 4c1cda5..34d92b1 100644 --- a/utils/structx/ordered_map_bench_test.go +++ b/structx/ordered_map_bench_test.go @@ -4,7 +4,7 @@ import ( "math/rand" "testing" - "github.com/lif0/pkg/utils/structx" + "github.com/lif0/pkg/structx" ) func makeInts(n int) ([]int, []int) { diff --git a/utils/structx/ordered_map_test.go b/structx/ordered_map_test.go similarity index 99% rename from utils/structx/ordered_map_test.go rename to structx/ordered_map_test.go index 267e5e1..0ca945b 100644 --- a/utils/structx/ordered_map_test.go +++ b/structx/ordered_map_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/lif0/pkg/utils/structx" + "github.com/lif0/pkg/structx" ) func Test_OrderedMap_Iter(t *testing.T) { diff --git a/sync/CHANGELOG.md b/sync/CHANGELOG.md deleted file mode 100644 index 57afe6a..0000000 --- a/sync/CHANGELOG.md +++ /dev/null @@ -1,14 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [Unreleased] YYYY-MM-DD -### Added -### Fixed -### Changed - -## [v1.2.0] 2025-10-29 -### Added -- Set minimum go version as 1.19 by @lif0 \ No newline at end of file diff --git a/sync/README.md b/sync/README.md deleted file mode 100644 index 9566dbb..0000000 --- a/sync/README.md +++ /dev/null @@ -1,191 +0,0 @@ -# package sync - -[![build](https://github.com/lif0/pkg/workflows/build/badge.svg)](https://github.com/lif0/pkg/workflows/build/badge.svg) -[![go reference](https://pkg.go.dev/badge/github.com/lif0/pkg.svg)](https://pkg.go.dev/github.com/lif0/pkg/sync) -![last version](https://img.shields.io/github/v/tag/lif0/pkg?label=latest&filter=sync/*) -[![sync coverage](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Flif0%2Fpkg%2Frefs%2Fheads%2Fmain%2F.github%2Fassets%2Fbadges%2Fcoverage-sync.json)](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Flif0%2Fpkg%2Frefs%2Fheads%2Fmain%2F.github%2Fassets%2Fbadges%2Fcoverage-sync.json) -[![sync report card](https://goreportcard.com/badge/github.com/lif0/pkg/sync)](https://goreportcard.com/report/github.com/lif0/pkg/sync) - -## Contents - -- [Overview](#-overview) -- [Requirements](#️-requirements) -- [Installation](#-installation) -- [Features](#-features) - - [ReentrantMutex](#reentrantmutex) - - [Performance](#performance) - - [Example](#example) -- [Roadmap](#️-roadmap) -- [License](#-license) - ---- - -## 📋 Overview - -The `sync` package provides advanced synchronization primitives for Go, designed for correctness, performance, and ease of use in concurrent programming. - -For full documentation, see [https://pkg.go.dev/github.com/lif0/pkg/sync](https://pkg.go.dev/github.com/lif0/pkg/sync). - ---- - -## ⚙️ Requirements - -- **go 1.19 or higher** - -## 📦 Installation - -To add this package to your project, use `go get`: - -```bash -go get github.com/lif0/pkg/sync@latest -``` - -Import the sync extension in your code: - -```go -import "github.com/lif0/pkg/sync" -``` - ---- - -## ✨ Features - -### ReentrantMutex - -The `ReentrantMutex` type provides a reentrant mutual exclusion lock that allows the same goroutine to acquire the lock multiple times without deadlocking. It supports recursive locking, ownership tracking, and methods like `Lock` and `Unlock`. - -Important details: - -- Panics on unlocking an unlocked mutex. -- Panics on unlocking from a different goroutine than the owner. -- Panics if recursion count goes negative. - -#### Performance - -```bash -goos: darwin -goarch: arm64 -pkg: github.com/lif0/pkg/sync -cpu: Apple M2 -BenchmarkMutexes/sync.Mutex-8 155_743_212 7.684 ns/op 0 B/op 0 allocs/op -BenchmarkMutexes/sync.RWMutex-8 71_501_988 16.49 ns/op 0 B/op 0 allocs/op -BenchmarkMutexes/sync.ReentrantMutex-8 65_857_020 17.82 ns/op 0 B/op 0 allocs/op - -BenchmarkMutexesParallel/sync.MutexParallel-8 13_736_034 73.02 ns/op 0 B/op 0 allocs/op -BenchmarkMutexesParallel/sync.RWMutexParallel-8 14_190_777 84.19 ns/op 0 B/op 0 allocs/op -BenchmarkMutexesParallel/sync.ReentrantMutexParallel-8 35_037_007 34.84 ns/op 0 B/op 0 allocs/op -``` - -#### Example - -##### Example: Basic Usage - -```go -package main - -import ( - "fmt" - - "github.com/lif0/pkg/sync" -) - -func main() { - // Create a new reentrant mutex - rm := sync.ReentrantMutex{} - - // Acquire the lock - rm.Lock() - fmt.Println("Acquired lock") - - // Perform critical section work - // ... - - // Release the lock - rm.Unlock() - fmt.Println("Released lock") -} -``` - -##### Example: Recursive Locking - -```go -package main - -import ( - "fmt" - - "github.com/lif0/pkg/sync" -) - -func recursiveFunction(rm *sync.ReentrantMutex, depth int) { - rm.Lock() - defer rm.Unlock() - - fmt.Printf("Recursion depth: %d\n", depth) - - if depth > 0 { - recursiveFunction(rm, depth-1) - } -} - -func main() { - rm := sync.ReentrantMutex{} - - recursiveFunction(rm, 3) -} -``` - -##### Example: Contention Handling - -```go -package main - -import ( - "fmt" - "sync" - "time" - - "github.com/lif0/pkg/sync" -) - -func main() { - rm := sync.NewReentrantMutex() - - rm.Lock() - fmt.Println("Main goroutine acquired lock") - - wg := sync.WaitGroup{} - wg.Add(1) - - go func() { - defer wg.Done() - - fmt.Println("Worker trying to acquire lock...") - rm.Lock() - fmt.Println("Worker acquired lock") - rm.Unlock() - }() - - time.Sleep(1 * time.Second) - rm.Unlock() - fmt.Println("Main goroutine released lock") - - wg.Wait() -} -``` - ---- - -## 🗺️ Roadmap - -The future direction of this package is community-driven! Ideas and contributions are highly welcome. - -☹️ No idea - -Contributions and feature suggestions are welcome 🤗. - ---- - -## 📄 License - -[MIT](./LICENSE) \ No newline at end of file diff --git a/sync/empty.go b/sync/empty.go deleted file mode 100644 index e587eff..0000000 --- a/sync/empty.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package sync provides synchronization utilities. -package sync diff --git a/concurrency/lock.go b/syncx/lock.go similarity index 96% rename from concurrency/lock.go rename to syncx/lock.go index 2de8600..b4feeba 100644 --- a/concurrency/lock.go +++ b/syncx/lock.go @@ -1,4 +1,4 @@ -package concurrency +package syncx import "sync" diff --git a/concurrency/lock_test.go b/syncx/lock_test.go similarity index 82% rename from concurrency/lock_test.go rename to syncx/lock_test.go index 680be1b..f970c65 100644 --- a/concurrency/lock_test.go +++ b/syncx/lock_test.go @@ -1,17 +1,17 @@ -package concurrency_test +package syncx_test import ( "sync" "testing" - "github.com/lif0/pkg/concurrency" + "github.com/lif0/pkg/syncx" ) func TestWithLock_ActionExecuted(t *testing.T) { var mu sync.Mutex called := false - concurrency.WithLock(&mu, func() { + syncx.WithLock(&mu, func() { called = true }) @@ -22,7 +22,7 @@ func TestWithLock_ActionExecuted(t *testing.T) { func TestWithLock_ActionNil(t *testing.T) { var mu sync.Mutex - concurrency.WithLock(&mu, nil) + syncx.WithLock(&mu, nil) } func TestWithLock_LockerNil(t *testing.T) { @@ -34,7 +34,7 @@ func TestWithLock_LockerNil(t *testing.T) { } }() - concurrency.WithLock(mu, func() {}) + syncx.WithLock(mu, func() {}) } func TestWithLock_MutexActuallyLocks(t *testing.T) { @@ -50,7 +50,7 @@ func TestWithLock_MutexActuallyLocks(t *testing.T) { go func() { defer wg.Done() for j := 0; j < increments; j++ { - concurrency.WithLock(&mu, func() { + syncx.WithLock(&mu, func() { counter++ }) } diff --git a/sync/noCopy.go b/syncx/noCopy.go similarity index 96% rename from sync/noCopy.go rename to syncx/noCopy.go index 3509eb5..d760386 100644 --- a/sync/noCopy.go +++ b/syncx/noCopy.go @@ -1,4 +1,4 @@ -package sync +package syncx // noCopy may be added to structs which must not be copied // after the first use. diff --git a/sync/noCopy_internal_test.go b/syncx/noCopy_internal_test.go similarity index 94% rename from sync/noCopy_internal_test.go rename to syncx/noCopy_internal_test.go index 9c69890..2c43546 100644 --- a/sync/noCopy_internal_test.go +++ b/syncx/noCopy_internal_test.go @@ -1,4 +1,4 @@ -package sync +package syncx import ( "testing" diff --git a/sync/reentrant_mutex.go b/syncx/reentrant_mutex.go similarity index 97% rename from sync/reentrant_mutex.go rename to syncx/reentrant_mutex.go index f32f450..fe53286 100644 --- a/sync/reentrant_mutex.go +++ b/syncx/reentrant_mutex.go @@ -1,5 +1,5 @@ -// Package sync provides sync utilities. -package sync +// Package syncx provides synchronization utilities. +package syncx import ( "errors" diff --git a/sync/reentrant_mutex_bench.txt b/syncx/reentrant_mutex_bench.txt similarity index 100% rename from sync/reentrant_mutex_bench.txt rename to syncx/reentrant_mutex_bench.txt diff --git a/sync/reentrant_mutex_bench_test.go b/syncx/reentrant_mutex_bench_test.go similarity index 99% rename from sync/reentrant_mutex_bench_test.go rename to syncx/reentrant_mutex_bench_test.go index ed43117..c89e3ab 100644 --- a/sync/reentrant_mutex_bench_test.go +++ b/syncx/reentrant_mutex_bench_test.go @@ -1,4 +1,4 @@ -package sync +package syncx import ( "reflect" diff --git a/sync/reentrant_mutex_test.go b/syncx/reentrant_mutex_test.go similarity index 99% rename from sync/reentrant_mutex_test.go rename to syncx/reentrant_mutex_test.go index fb60804..ac89e03 100644 --- a/sync/reentrant_mutex_test.go +++ b/syncx/reentrant_mutex_test.go @@ -1,4 +1,4 @@ -package sync +package syncx import ( "math/rand" diff --git a/concurrency/semaphore_chan.go b/syncx/semaphore_chan.go similarity index 96% rename from concurrency/semaphore_chan.go rename to syncx/semaphore_chan.go index 25c2a52..44a61dc 100644 --- a/concurrency/semaphore_chan.go +++ b/syncx/semaphore_chan.go @@ -1,4 +1,4 @@ -package concurrency +package syncx import "context" @@ -76,7 +76,7 @@ func (s *Semaphore) Release() { case <-s.ch: return default: - panic("concurrency.Semaphore: release without matching acquire") + panic("syncx.Semaphore: release without matching acquire") } } diff --git a/concurrency/semaphore_chan_test.go b/syncx/semaphore_chan_test.go similarity index 90% rename from concurrency/semaphore_chan_test.go rename to syncx/semaphore_chan_test.go index 05193c8..35358d8 100644 --- a/concurrency/semaphore_chan_test.go +++ b/syncx/semaphore_chan_test.go @@ -1,11 +1,11 @@ -package concurrency_test +package syncx_test import ( "context" "testing" "time" - "github.com/lif0/pkg/concurrency" + "github.com/lif0/pkg/syncx" ) func mustPanic(t *testing.T, fn func()) { @@ -19,7 +19,7 @@ func mustPanic(t *testing.T, fn func()) { } func TestNewSemaphore_UnlimitedAndLimited(t *testing.T) { - s0 := concurrency.NewSemaphore(0) + s0 := syncx.NewSemaphore(0) if got := s0.Cap(); got != 0 { t.Fatalf("Cap(unlimited) = %d, want 0", got) } @@ -27,7 +27,7 @@ func TestNewSemaphore_UnlimitedAndLimited(t *testing.T) { t.Fatalf("InUse(unlimited) = %d, want 0", got) } - s3 := concurrency.NewSemaphore(3) + s3 := syncx.NewSemaphore(3) if got := s3.Cap(); got != 3 { t.Fatalf("Cap(limited) = %d, want 3", got) } @@ -37,7 +37,7 @@ func TestNewSemaphore_UnlimitedAndLimited(t *testing.T) { } func TestNilSemaphore_Behavior(t *testing.T) { - var s *concurrency.Semaphore // nil receiver must be safe + var s *syncx.Semaphore // nil receiver must be safe // no panics and "unlimited" utils s.Acquire() @@ -57,7 +57,7 @@ func TestNilSemaphore_Behavior(t *testing.T) { } func TestUnlimitedSemaphore_Methods(t *testing.T) { - s := concurrency.NewSemaphore(0) + s := syncx.NewSemaphore(0) // Acquire / Release are no-ops s.Acquire() @@ -80,7 +80,7 @@ func TestUnlimitedSemaphore_Methods(t *testing.T) { } func TestAcquireRelease_LimitedAndTryAcquire(t *testing.T) { - s := concurrency.NewSemaphore(2) + s := syncx.NewSemaphore(2) // acquire to capacity s.Acquire() @@ -118,7 +118,7 @@ func TestAcquireRelease_LimitedAndTryAcquire(t *testing.T) { } func TestAcquireBlocksUntilRelease(t *testing.T) { - s := concurrency.NewSemaphore(1) + s := syncx.NewSemaphore(1) // fill the only slot s.Acquire() @@ -151,7 +151,7 @@ func TestAcquireBlocksUntilRelease(t *testing.T) { } func TestAcquireContext_Canceled(t *testing.T) { - s := concurrency.NewSemaphore(1) + s := syncx.NewSemaphore(1) s.Acquire() // fill ctx, cancel := context.WithTimeout(context.Background(), 30*time.Millisecond) @@ -172,7 +172,7 @@ func TestAcquireContext_Canceled(t *testing.T) { } func TestAcquireContext_Succeeds(t *testing.T) { - s := concurrency.NewSemaphore(2) + s := syncx.NewSemaphore(2) if err := s.AcquireContext(context.Background()); err != nil { t.Fatalf("AcquireContext should succeed, got %v", err) } @@ -183,7 +183,7 @@ func TestAcquireContext_Succeeds(t *testing.T) { } func TestRelease_PanicsOnOverRelease(t *testing.T) { - s := concurrency.NewSemaphore(1) + s := syncx.NewSemaphore(1) // over-release on limited semaphore must panic mustPanic(t, func() { @@ -191,6 +191,6 @@ func TestRelease_PanicsOnOverRelease(t *testing.T) { }) // but on unlimited it's a no-op - su := concurrency.NewSemaphore(0) + su := syncx.NewSemaphore(0) su.Release() // must not panic } diff --git a/concurrency/sync_value.go b/syncx/sync_value.go similarity index 99% rename from concurrency/sync_value.go rename to syncx/sync_value.go index a4710e6..8352a14 100644 --- a/concurrency/sync_value.go +++ b/syncx/sync_value.go @@ -1,4 +1,4 @@ -package concurrency +package syncx import "sync" diff --git a/concurrency/sync_value_banch_test.go b/syncx/sync_value_banch_test.go similarity index 90% rename from concurrency/sync_value_banch_test.go rename to syncx/sync_value_banch_test.go index 2101b73..7a2556d 100644 --- a/concurrency/sync_value_banch_test.go +++ b/syncx/sync_value_banch_test.go @@ -1,4 +1,4 @@ -package concurrency_test +package syncx_test import ( "fmt" @@ -6,7 +6,7 @@ import ( "sync/atomic" "testing" - concurrency "github.com/lif0/pkg/concurrency" + "github.com/lif0/pkg/syncx" ) func benchReadHeavy(b *testing.B, readFn func(), writeFn func()) { @@ -56,7 +56,7 @@ func benchMixed(b *testing.B, readFn func(), writeFn func()) { func Benchmark_Int64_ReadHeavy(b *testing.B) { b.Run("SyncValue", func(b *testing.B) { - sv := concurrency.NewSyncValue[int64]() + sv := syncx.NewSyncValue[int64]() benchReadHeavy(b, func() { sv.ReadValue(func(v *int64) { _ = *v }) @@ -77,7 +77,7 @@ func Benchmark_Int64_ReadHeavy(b *testing.B) { func Benchmark_Int64_WriteHeavy(b *testing.B) { b.Run("SyncValue", func(b *testing.B) { - sv := concurrency.NewSyncValue[int64]() + sv := syncx.NewSyncValue[int64]() benchWriteHeavy(b, func() { sv.MutateValue(func(v *int64) { *v++ }) }) }) b.Run("Atomic", func(b *testing.B) { @@ -88,7 +88,7 @@ func Benchmark_Int64_WriteHeavy(b *testing.B) { func Benchmark_Int64_Mixed(b *testing.B) { b.Run("SyncValue", func(b *testing.B) { - sv := concurrency.NewSyncValue[int64]() + sv := syncx.NewSyncValue[int64]() benchMixed(b, func() { sv.ReadValue(func(v *int64) { _ = *v }) @@ -109,7 +109,7 @@ func Benchmark_Int64_Mixed(b *testing.B) { func Benchmark_Map_Mixed(b *testing.B) { b.Run("SyncValue", func(b *testing.B) { - sv := concurrency.NewSyncValue[map[string]int](map[string]int{"x": 0}) + sv := syncx.NewSyncValue[map[string]int](map[string]int{"x": 0}) benchMixed(b, func() { sv.ReadValue(func(v *map[string]int) { _ = (*v)["x"] }) @@ -139,7 +139,7 @@ func Benchmark_Map_Mixed(b *testing.B) { func Benchmark_Complex_Mixed(b *testing.B) { b.Run("SyncValue", func(b *testing.B) { - sv := concurrency.NewSyncValue[complexStruct](complexStruct{Flag: true, Nums: []int{1}, Index: map[string]int{"x": 1}}) + sv := syncx.NewSyncValue[complexStruct](complexStruct{Flag: true, Nums: []int{1}, Index: map[string]int{"x": 1}}) benchMixed(b, func() { sv.ReadValue(func(v *complexStruct) { diff --git a/concurrency/sync_value_test.go b/syncx/sync_value_test.go similarity index 91% rename from concurrency/sync_value_test.go rename to syncx/sync_value_test.go index 7b20dfd..c36549a 100644 --- a/concurrency/sync_value_test.go +++ b/syncx/sync_value_test.go @@ -1,11 +1,11 @@ -package concurrency_test +package syncx_test import ( "sync" "testing" "time" - "github.com/lif0/pkg/concurrency" + "github.com/lif0/pkg/syncx" "github.com/stretchr/testify/assert" ) @@ -21,7 +21,7 @@ func Test_Snapshot(t *testing.T) { t.Run("ok/int_snapshot_not_shared", func(t *testing.T) { t.Parallel() // arrange - sv := concurrency.NewSyncValue[int]() + sv := syncx.NewSyncValue[int]() // act sv.MutateValue(func(v *int) { *v = 12 @@ -42,7 +42,7 @@ func Test_Snapshot(t *testing.T) { t.Run("ok/slice_snapshot_not_shared_deep_copy", func(t *testing.T) { t.Parallel() // arrange - sv := concurrency.NewSyncValue[[]int]([]int{1, 2, 3}) + sv := syncx.NewSyncValue[[]int]([]int{1, 2, 3}) var snap []int // act sv.ReadValue(func(v *[]int) { @@ -60,7 +60,7 @@ func Test_Snapshot(t *testing.T) { t.Run("ok/map_snapshot_not_shared_deep_copy", func(t *testing.T) { t.Parallel() // arrange - sv := concurrency.NewSyncValue[map[string]int](map[string]int{"a": 1, "b": 2}) + sv := syncx.NewSyncValue[map[string]int](map[string]int{"a": 1, "b": 2}) snap := make(map[string]int) // act sv.ReadValue(func(v *map[string]int) { @@ -84,7 +84,7 @@ func Test_Snapshot(t *testing.T) { Nums: []int{1, 2, 3}, Index: map[string]int{"x": 1}, } - sv := concurrency.NewSyncValue[complexStruct](init) + sv := syncx.NewSyncValue[complexStruct](init) var snap complexStruct // act @@ -116,7 +116,7 @@ func Test_IntValue(t *testing.T) { t.Run("ok/basic_set_get", func(t *testing.T) { t.Parallel() // arrange - sv := concurrency.NewSyncValue[int]() + sv := syncx.NewSyncValue[int]() // act sv.MutateValue(func(v *int) { *v = 12 @@ -135,7 +135,7 @@ func Test_IntValue(t *testing.T) { const writers = 4 const readers = writers const perWorker = 1000 - sv := concurrency.NewSyncValue[int](0) + sv := syncx.NewSyncValue[int](0) var wg sync.WaitGroup wg.Add(writers + readers) @@ -187,7 +187,7 @@ func Test_SliceValue(t *testing.T) { t.Run("ok/basic_append_and_read", func(t *testing.T) { t.Parallel() // arrange - sv := concurrency.NewSyncValue[[]int]([]int{1, 2}) + sv := syncx.NewSyncValue[[]int]([]int{1, 2}) // act sv.MutateValue(func(v *[]int) { *v = append(*v, 3) @@ -203,7 +203,7 @@ func Test_SliceValue(t *testing.T) { t.Run("race/concurrent_append_and_read_len", func(t *testing.T) { t.Parallel() // arrange - sv := concurrency.NewSyncValue[[]int]() + sv := syncx.NewSyncValue[[]int]() const writers = 4 const readers = writers const perWriter = 300 @@ -259,7 +259,7 @@ func Test_MapValue(t *testing.T) { t.Run("ok/basic_put_get", func(t *testing.T) { t.Parallel() // arrange - sv := concurrency.NewSyncValue[map[string]int](map[string]int{}) + sv := syncx.NewSyncValue[map[string]int](map[string]int{}) // act sv.MutateValue(func(v *map[string]int) { (*v)["a"] = 1 @@ -275,7 +275,7 @@ func Test_MapValue(t *testing.T) { t.Run("race/concurrent_increments", func(t *testing.T) { t.Parallel() // arrange - sv := concurrency.NewSyncValue[map[string]int](map[string]int{"x": 0}) + sv := syncx.NewSyncValue[map[string]int](map[string]int{"x": 0}) const writers = 4 const readers = writers const perWorker = 400 @@ -330,7 +330,7 @@ func Test_StructValue(t *testing.T) { t.Parallel() // arrange init := complexStruct{Flag: false, Nums: []int{1, 2}, Index: map[string]int{"a": 1}} - sv := concurrency.NewSyncValue[complexStruct](init) + sv := syncx.NewSyncValue[complexStruct](init) // act sv.MutateValue(func(v *complexStruct) { v.Flag = true @@ -348,7 +348,7 @@ func Test_StructValue(t *testing.T) { t.Run("race/concurrent_read_write", func(t *testing.T) { t.Parallel() // arrange - sv := concurrency.NewSyncValue[complexStruct](complexStruct{ + sv := syncx.NewSyncValue[complexStruct](complexStruct{ Flag: false, Nums: []int{}, Index: map[string]int{}, diff --git a/utils/CHANGELOG.md b/utils/CHANGELOG.md deleted file mode 100644 index 00ed24c..0000000 --- a/utils/CHANGELOG.md +++ /dev/null @@ -1,20 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [Unreleased] YYYY-MM-DD -### Added -### Fixed -### Changed - -## [v1.2.0] 2025-10-29 -### Added -- [[PKG-18]](https://github.com/lif0/pkg/issues/18) Set minimum go version as 1.23; by @lif0 -- [[PKG-18]](https://github.com/lif0/pkg/issues/18) Add struct OrderedMap[K]V; by @lif0 -- [[PKG-28]](https://github.com/lif0/pkg/issues/28) Add struct ObjectPool[T]; by @lif0 - -## [v1.0.1] -### Added -- [PKG-16] feat(utils/errx): add MultiError structure; \ No newline at end of file diff --git a/utils/README.md b/utils/README.md deleted file mode 100644 index d7d4145..0000000 --- a/utils/README.md +++ /dev/null @@ -1,329 +0,0 @@ -# package utils - -[![build](https://github.com/lif0/pkg/workflows/build/badge.svg)](https://github.com/lif0/pkg/workflows/build/badge.svg) -[![Go Reference](https://pkg.go.dev/badge/github.com/lif0/pkg.svg)](https://pkg.go.dev/github.com/lif0/pkg/utils) -![last version](https://img.shields.io/github/v/tag/lif0/pkg?label=latest&filter=utils/*) -[![utils coverage](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Flif0%2Fpkg%2Frefs%2Fheads%2Fmain%2F.github%2Fassets%2Fbadges%2Fcoverage-utils.json)](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Flif0%2Fpkg%2Frefs%2Fheads%2Fmain%2F.github%2Fassets%2Fbadges%2Fcoverage-utils.json) -[![utils report card](https://goreportcard.com/badge/github.com/lif0/pkg/utils)](https://goreportcard.com/report/github.com/lif0/pkg/utils) - -## Contents - -- [Overview](#-overview) -- [Requirements](#️-requirements) -- [Installation](#-installation) -- [Package: `reflect`](#-package-reflect) - - [Function: `EstimatePayloadOf`](#function-estimatepayloadof) - - [Supported Types](#-supported-types) - - [Performance](#performance-notes) - - [Use Case](#-use-case) - - [Examples](#-examples) -- [Package: `errx`](#-package-errx) - - [MultiError](#multierror) -- [Package: `structx`](#-package-structx) - - [OrderedMap](#orderedmap) -- [Roadmap](#️-roadmap) -- [License](#-license) - ---- - -## 📋 Overview - -The `utils` module provides a set of lightweight, focused utility packages designed to extend Go's standard library with commonly needed functionality. These packages follow Go's philosophy of simplicity and efficiency, offering well-tested solutions for everyday development challenges. - -For full documentation, see [https://pkg.go.dev/github.com/lif0/pkg/utils](https://pkg.go.dev/github.com/lif0/pkg/utils). - ---- - -## ⚙️ Requirements - -- **go 1.23 or higher** - -## 📦 Installation - -To add this package to your project, use `go get`: - -```bash -go get github.com/lif0/pkg/utils@latest -``` - -Import the reflect extension in your code: - -```go -import "github.com/lif0/pkg/utils/reflect" -``` - ---- - -## 📚 Package `reflect` - -### Function: `EstimatePayloadOf` - -```go -func EstimatePayloadOf(v any) int -``` - -Returns an **approximate payload size (in bytes)** of the given value. It is designed for efficiency and is allocation-free for supported types - -⚠️ **Return Value and Errors** - -- Returns the estimated size in bytes for supported types. -- Returns **`reflect.ErrFailEstimatePayload`** = `-1` if the type is not supported or cannot be estimated. - -#### Performance Notes - -This function performs **zero allocations** and runs with **0 B/op** for supported types. [See benchmark](/utils/reflect/estimate_payload_bench_out.txt) - -- **No memory allocations** — `0 B/op` for all primitive types. -- **Reflection** is used only for arrays and structs: - - Supports any primitive types in arrays. - - Supports only `time.Time{}` for structs. -- For arrays `[N]T`, prefer passing `*[N]T` to avoid value copying. - -Check: - -- [Benchmarks](/utils/reflect/estimate_payload_bench_test.go) -- [Tests](/utils/reflect/estimate_payload_test.go) - -#### ✅ Supported Types - -Scalar types (and pointers to them): - -- `int`, `int8`, `int16`, `int32` (`rune`), `int64` -- `uint`, `uint8` (`byte`), `uint16`, `uint32`, `uint64`, `uintptr` -- `float32`, `float64` -- `complex64`, `complex128` -- `bool` -- `string` -- `time.Time`, `time.Duration` - -Containers: - -- `[]T`, `[]*T`, `*[]T`, `*[]*T` — slices -- `[N]T`, `*[N]T`, `[N]*T`, `*[N]*T` — arrays (via reflection) - -For pointers and slices, `nil` is treated as zero-size. -For `string` and `[]string`, the actual content size is summed. - -If the type is not supported, the function returns `reflect.ErrFailEstimatePayload(-1)`. - -#### 💡 Use Case - -Calculate request/response sizes for logging or monitoring, such as writing to a span in a database provider library. - -#### 🧪 Examples - -Estimate an int value: - -```go -var v int = 42 -n := EstimatePayloadOf(v) -// n == 8 on 64-bit systems -``` - -Estimate a string: - -```go -s := EstimatePayloadOf("hello") -// s == 5 (len("hello")) -``` - -Estimate a slice of strings: - -```go -names := []string{"John", "Doe"} -size := EstimatePayloadOf(names) -// size == len("John") + len("Doe") == 4 + 3 == 7 -``` - -Estimate a slice with nil strings: - -```go -names := []string{"John", nil} -size := EstimatePayloadOf(names) -// size == len("John") + len("") == 4 + 0 == 4 -``` - -Estimate a struct: - -```go -type User struct { - ID int64 - Name string -} -u := User{ID: 123, Name: "Alice"} -size := EstimatePayloadOf(u) -// size == reflect.ErrFailEstimatePayload(-1), because it is a custom struct -``` - -Estimate an array (pass by pointer for performance): - -```go -var arr [1000]int32 -size := EstimatePayloadOf(&arr) -// size == 1000 * 4 == 4000 -``` - ---- - - - - - -## 📚 Package `errx` - -Provide additional feature for error. - -### MultiError - -MultiError is a slice of errors implementing the error interface. - - -| Item | Signature | Purpose | Notes | -| ----------- | ----------------------------------------- | ------------------------------------------------ | --------------------------------------------------------------------------- | -| Type | `type MultiError []error` | Slice of `error` that itself implements `error`. | Zero-value is usable. | -| Append | `func (m *MultiError) Append(err error)` | Adds a non-nil error to the set. | No-op for `nil`; safe on zero value. | -| MaybeUnwrap | `func (m MultiError) MaybeUnwrap() error` | Returns the simplest meaningful error. | `len==0 → nil`, `len==1 → m[0]`, otherwise `m` itself. | -| Error | `func (m MultiError) Error() string` | Human-readable, counted, bulleted message. | `""` when empty; format: `" error(s) occurred:\n* \n* ..."`. | -| IsEmpty | `func (m MultiError) IsEmpty() bool` | Quick emptiness check. | `true` when there are no errors. | - - - -#### Example - -```go -var me errx.MultiError -me.Append(validateName("")) -me.Append(validateAge(-1)) -if err := me.MaybeUnwrap(); err != nil { - // 2 error(s) occurred: - // * name must not be empty - // * age must be >= 0 - fmt.Println(err) -} -``` - -#### Batch Example - -```go -var me errx.MultiError -for _, job := range jobs { - if err := job.Run(); err != nil { - me.Append(fmt.Errorf("job %q: %w", job.Name, err)) - } -} -return me.MaybeUnwrap() -``` - -## 📚 Package `structx` - -Provide additional golang type. - -### OrderedMap - -OrderedMap is a map[Type]Type1-like collection that preserves the order in which keys were inserted. It behaves like a regular map but allows deterministic iteration over its elements. - -Useful: -Imagine you are making a closer or graceful shutdown lib, and you need to register/unregister some functions/service in it, and finally handle them in the order they were added. Use it structure. You are welcome🤗 - -The structure provide provice - -#### API - -| Func | Complexity (time / mem) | -| ---------------------------------------------------------------------- | ---------------------------- | -| `(m *OrderedMap[K, V]) Get(key K) (V, bool)` | O(1) / O(1) | -| `(m *OrderedMap[K, V]) Put(key K, value V)` | O(1) / O(1) | -| `(m *OrderedMap[K, V]) GetValues() []V` | O(N) / O(N) | -| `(m *OrderedMap[K, V]) Iter() []V` | for k,v := range m.Iter() {} | -| `structx.Delete[K comparable, V any](m *OrderedMap[K, V], key K)` | O(1) / O(1) | - - -#### Benchmarks: OrderedMap[Type, Type1] vs map[Type]Type1 - -Environment: - -```text -goos: darwin -goarch: arm64 -cpu: Apple M2 -pkg: github.com/lif0/pkg/utils/structx -``` - -##### TL;DR - -- Inserts (`put`): `map` is faster and uses less memory. -- Lookups (`get_hit`): `OrderedMap` is faster on string keys; a bit slower on int keys. -- Deletes (`delete`): almost the same. -- Iteration (`iterate_values`): OrderedMap is much faster and ordered. - ---- - -##### Key/Value: `int, int` - -| Operation | ns/op (`OrderedMap`) | ns/op (`map`) | B/op (`OrderedMap`) | B/op (`map`) | allocs/op (`OrderedMap`) | allocs/op (`map`) | time (`OrderedMap` vs `map`) | -| -------------- | --------------: | ------------: | -------------: | -----------: | ------------------: | ----------------: | -------------------------: | -| put | 220,267 | 100,546 | 705,330 | 295,557 | 39 | 33 | **+119.1%** (2.19× slower) | -| get_hit | 74,626 | 65,668 | 0 | 0 | 0 | 0 | **+13.6%** (1.14× slower) | -| delete | 19,322 | 19,348 | 0 | 0 | 0 | 0 | **−0.1%** (≈ same) | -| iterate_values | 11,131 | 61,998 | 0 | 0 | 0 | 0 | **−82.0%** (5.6× faster) | - -##### Key/Value: `string, []string` - -| Operation | ns/op (`OrderedMap`) | ns/op (`map`) | B/op (`OrderedMap`) | B/op (`map`) | allocs/op (`OrderedMap`) | allocs/op (`map`) | time (Ordered vs `map`) | -| -------------- | --------------: | ------------: | -------------: | -----------: | ------------------: | ----------------: | ------------------------: | -| put | 507,196 | 360,451 | 1,084,229 | 787,101 | 40 | 33 | **+40.7%** (1.41× slower) | -| get_hit | 136,184 | 193,829 | 0 | 0 | 0 | 0 | **−29.7%** (1.43× faster) | -| delete | 20,713 | 20,758 | 0 | 0 | 0 | 0 | **−0.2%** (≈ same) | -| iterate_values | 17,822 | 63,645 | 0 | 0 | 0 | 0 | **−72.0%** (3.6× faster) | - -##### Key/Value: `string, ComplexStruct` - -| Operation | ns/op (`OrderedMap`) | ns/op (`map`) | B/op (`OrderedMap`) | B/op (`map`) | allocs/op (`OrderedMap`) | allocs/op (`map`) | time (Ordered vs `map`) | -| -------------- | --------------: | ------------: | -------------: | -----------: | ------------------: | ----------------: | ------------------------: | -| put | 493,887 | 329,433 | 1,166,137 | 918,167 | 40 | 33 | **+49.9%** (1.50× slower) | -| get_hit | 117,553 | 174,528 | 0 | 0 | 0 | 0 | **−32.6%** (1.49× faster) | -| delete | 20,471 | 20,420 | 0 | 0 | 0 | 0 | **+0.2%** (≈ same) | -| iterate_values | 19,729 | 62,435 | 0 | 0 | 0 | 0 | **−68.4%** (3.2× faster) | - -##### How to run - -```bash -go test -benchmem -run=^$ -bench ^Benchmark_OrderedMap -v github.com/lif0/pkg/utils/structx -``` - - -#### Examples - -```go -import "github.com/lif0/pkg/utils/structx" - - -func main() { - m := structx.NewOrderedMap[string, int]() - - m.Put("key", 10) - - v, ok := m.Get("key") // v = 10 - - structx.Delete(m, "key") // or build-in func m.Delete("key"), but prefer build-in function. - - for k,v := range m.Iter() { - fmt.Println(k,v) - } -} -``` - -## 🗺️ Roadmap - -- [ ] improve Object Order -- [ ] improve perf for OrderedMap - ---- - -Contributions and feature suggestions are welcome 🤗. - ---- - -## 📄 License - -[MIT](./LICENSE) diff --git a/utils/empty.go b/utils/empty.go deleted file mode 100644 index 61e64db..0000000 --- a/utils/empty.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package utils provides a collection of utility functions for Go applications. -package utils diff --git a/utils/go.mod b/utils/go.mod deleted file mode 100644 index 52d24e1..0000000 --- a/utils/go.mod +++ /dev/null @@ -1,11 +0,0 @@ -module github.com/lif0/pkg/utils - -go 1.23 - -require github.com/stretchr/testify v1.11.1 - -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) diff --git a/utils/go.sum b/utils/go.sum deleted file mode 100644 index c4c1710..0000000 --- a/utils/go.sum +++ /dev/null @@ -1,10 +0,0 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= -github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From ed84e6f34ef40c65c0f7be5568e307c0e8897be2 Mon Sep 17 00:00:00 2001 From: lif0 <22912194+lif0@users.noreply.github.com> Date: Wed, 17 Jun 2026 15:50:09 +0300 Subject: [PATCH 2/2] docs: update README.md; --- CONTRIBUTING.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7f5c9fd..fd1be9f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contributing to pkg -Thank you for your interest in contributing to **pkg**! This repository is a collection of low-level, dependency-free (mostly), high-performance Go packages designed for maximum efficiency, zero allocations where possible, and clean, idiomatic APIs. We aim to maintain production-grade quality with strong guarantees on stability and code quality. +Thank you for your interest in contributing to **pkg**! It's a small collection of low-level Go packages I use across my own projects. They're meant to be fast, idiomatic, and avoid external dependencies where possible. We aim to maintain production-grade quality with strong guarantees on stability and code quality. Contributions are welcome, whether it's reporting bugs, suggesting features, fixing issues, or adding new packages. All contributions help make this toolkit better for the Go community. diff --git a/README.md b/README.md index 188cafd..3935c4f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@
-

🚀A collection of low-level, dependency-free(mostly), high-performance Go packages🚀

+

Low-level Go packages I use across my own projects. Fast, and mostly dependency-free.