ladybird/Userland/Libraries/LibJS/Runtime/EnvironmentCoordinate.h
Andreas Kling 0f1f925532 LibJS: Shrink Identifier's environment coordinate cache
This patch does two things:

- We now use u32 instead of size_t for the hops and index fields
  in EnvironmentCoordinate. This means we're limited to an environment
  nesting level and variable count of 4Gs respectively.

- Instead of wrapping it in an Optional, EnvironmentCoordinate now has
  a custom valid/invalid state using a magic marker value.

These two changes reduce the size of Identifier by 16 bytes. :^)
2022-11-22 21:13:35 +01:00

24 lines
493 B
C++

/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Types.h>
#include <LibJS/Forward.h>
namespace JS {
struct EnvironmentCoordinate {
u32 hops { invalid_marker };
u32 index { invalid_marker };
bool is_valid() const { return hops != invalid_marker && index != invalid_marker; }
static constexpr u32 global_marker = 0xffffffff;
static constexpr u32 invalid_marker = 0xfffffffe;
};
}