GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — zlib: reduce code duplication · nodejs/node@b970c0b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_zlib.cc
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_zlib.cc‎

Copy file name to clipboardExpand all lines: src/node_zlib.cc
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,11 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
612612
return AllocForBrotli(data, real_size);
613613
}
614614

615+
static constexpr size_t reserveSizeAndAlign =
616+
std::max(sizeof(size_t), alignof(max_align_t));
617+
615618
static void* AllocForBrotli(void* data, size_t size) {
616-
constexpr size_t offset = std::max(sizeof(size_t), alignof(max_align_t));
617-
size += offset;
619+
size += reserveSizeAndAlign;
618620
CompressionStream* ctx = static_cast<CompressionStream*>(data);
619621
char* memory = UncheckedMalloc(size);
620622
if (memory == nullptr) [[unlikely]] {
@@ -623,16 +625,15 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
623625
*reinterpret_cast<size_t*>(memory) = size;
624626
ctx->unreported_allocations_.fetch_add(size,
625627
std::memory_order_relaxed);
626-
return memory + offset;
628+
return memory + reserveSizeAndAlign;
627629
}
628630

629631
static void FreeForZlib(void* data, void* pointer) {
630632
if (pointer == nullptr) [[unlikely]] {
631633
return;
632634
}
633635
CompressionStream* ctx = static_cast<CompressionStream*>(data);
634-
constexpr size_t offset = std::max(sizeof(size_t), alignof(max_align_t));
635-
char* real_pointer = static_cast<char*>(pointer) - offset;
636+
char* real_pointer = static_cast<char*>(pointer) - reserveSizeAndAlign;
636637
size_t real_size = *reinterpret_cast<size_t*>(real_pointer);
637638
ctx->unreported_allocations_.fetch_sub(real_size,
638639
std::memory_order_relaxed);

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.