Commit Graph

53 Commits

Author SHA1 Message Date
afd59b36cf Avoid extra copy in Vector/CowData push_back/insert
Update push_back/insert methods to move new item into CowData instead of copying
2025-11-11 12:19:35 -05:00
c993db9688 Add reserve_exact to CowData and Vector.
Change growth factor to be an indeterministic 1.5x.
Use `reserve_exact` in `FileAccess` to reduce on binary file loading RAM usage.

# Conflicts:
#	core/templates/cowdata.h
2025-10-01 11:57:40 +02:00
8f533897d8 Make CowData::reserve warn message when new capacity < size verbose, like other reserve methods. 2025-09-30 20:21:02 +02:00
1bf821c1e1 Store current capacity in CowData buffers, and rewrite most of it.
Add `reserve` to `CowData`, `Vector` and `Array`.

# Conflicts:
#	core/os/memory.h
#	core/templates/cowdata.h
2025-09-25 22:00:17 +02:00
5fda92451d Merge pull request #100145 from Ivorforce/memory-offset-func
Add `mem_aligned_address` to simplify data offset constants.
2025-09-25 14:57:09 -05:00
3ac159094f Add memory_get_offset to simplify data offset constants. 2025-09-25 20:55:33 +02:00
f6f1df7d73 Add 64-bit versions of core power of 2 functions 2025-06-01 23:11:12 -07:00
d2d57849de Add a safety check for CowData::_unref(), for when something tries to add elements during destruction. 2025-05-27 18:00:48 +02:00
4371aa864d Simplify Memory::memnew_arr_placement to always initialize memory, to force callers to make the decision of whether to initialize. 2025-05-22 22:25:12 +02:00
5538850d87 Core: Convert Pair/KeyValue to constexpr 2025-05-15 10:37:41 -05:00
01fc9aee6c Core: Modernize C headers with C++ equivalents 2025-05-02 08:23:01 -05:00
015a3b0434 Optimize / refactor CowData, combining resize and fork to avoid unnecessary reallocations. 2025-04-15 17:01:26 +02:00
b711d72e8f Remove unnecessary friend class declarations of CowData.
Use default implementations for various containers.
2025-04-11 18:26:08 +02:00
207a2b6472 Core: Integrate warning suppression macro helpers 2025-04-03 10:13:46 -05:00
f09ee0171a Style: Begin integrating simple .clangd fixes 2025-03-22 13:24:35 -05:00
49e860159a Move CowData find, rfind and count to Span. 2025-03-16 03:31:11 +01:00
75bc471965 Add is_zero_constructible to denote if a type can be semi-trivially constructed with all 0 bytes.
Optimize `CowData` and `LocalVector` resize for zero constructible types.
Mark several compatible types as `is_zero_constructible`.
2025-03-12 09:49:24 +01:00
605b62cd29 Add Span struct (replacing StrRange). Spans represent read-only access to a contiguous array, resembling std::span. 2025-03-09 18:19:51 +01:00
324512e11c Style: Replace header guards with #pragma once 2025-03-07 17:33:47 -06:00
25cd923ea1 Destruct CowData more graciously by avoiding accidentally exposing a half-destructed buffer. This can avoid problems if any of the destructed objects tries to access the data while it's being destructed. 2024-12-21 20:01:03 +01:00
151e7fc687 Merge pull request #100477 from Ivorforce/cowdata-move-insert-n-remove
Optimize `CowData` and `LocalVector` functions `.insert` and `.remove_at` by using move semantics.
2024-12-19 20:00:20 -06:00
1b8a2d930f Merge pull request #100474 from Ivorforce/cowdata-abstract-realloc
Abstract `CowData`'s reallocations into `_realloc` to consolidate duplicate logic.
2024-12-19 20:00:19 -06:00
8483d794ff Abstract CowData's reallocations into _realloc to consolidate duplicate logic. 2024-12-19 17:27:16 +01:00
361e3b4fe8 Core: Expand std::initializer_list support 2024-12-18 18:46:59 -06:00
a636c04244 Optimize CowData and LocalVector functions .insert and .remove_at by using move semantics. 2024-12-17 14:10:10 +01:00
57073ba14e Add move constructor and move assignment to CowData, String, Char16String, CharString and Vector. 2024-12-11 15:52:15 +01:00
0d350e7108 Set clang-format RemoveSemicolon rule to true
- Set clang-format `Standard` rule to `c++20`
2024-10-25 13:49:43 -04:00
f1d6677713 Merge pull request #95469 from bruvzg/cowdata_unref
`CowData` remove hardcoded offset and unused argument from `_unref`.
2024-08-16 10:36:28 +02:00
273ba27c2f CowData remove hardcoded offset and unused argument from _unref. 2024-08-13 08:53:45 +03:00
c1afe7dcdf Improve CowData::insert performance
Update CowData::insert to call ptrw() before loop, to avoid calling _copy_on_write for each item in the array, as well as repeated index checks in set and get.  For larger Vectors/Arrays, this makes inserts around 10x faster for ints, 3x faster for Strings, and 2x faster for Variants.  Less of an impact on smaller Vectors/Arrays, as a larger percentage of the time is spent allocating.
2024-07-15 14:01:19 -04:00
9903e6779b Enforce template syntax typename over class 2024-03-07 22:39:09 -06:00
7bcb419149 [Core] Improve CowData and Memory metadata alignment. 2024-02-05 17:30:02 +02:00
55ed34e37c Use '_v' shorthand for type traits and 'if constexpr' where appropriate 2024-02-02 15:43:21 +01:00
24fe0715b5 Promote CowData to 64 bits
Fixes a lot of bugs, please help me fill the list.
2024-01-19 17:41:10 +01:00
c48b189e14 Fix allocation size overflow check in CowData 2023-09-19 16:12:02 +02:00
893f889d74 [Core] Replace ERR_FAIL_COND with ERR_FAIL_NULL where applicable 2023-09-11 19:45:49 +02:00
d95794ec8a One Copyright Update to rule them all
As many open source projects have started doing it, we're removing the
current year from the copyright notice, so that we don't need to bump
it every year.

It seems like only the first year of publication is technically
relevant for copyright notices, and even that seems to be something
that many companies stopped listing altogether (in a version controlled
codebase, the commits are a much better source of date of publication
than a hardcoded copyright statement).

We also now list Godot Engine contributors first as we're collectively
the current maintainers of the project, and we clarify that the
"exclusive" copyright of the co-founders covers the timespan before
opensourcing (their further contributions are included as part of Godot
Engine contributors).

Also fixed "cf." Frenchism - it's meant as "refer to / see".
2023-01-05 13:25:55 +01:00
54418ea659 Remove NO_THREADS fallback code, Godot 4 requires thread support
This also removes `OS::can_use_threads` from the public API since it's always
true.
2022-10-03 11:23:26 +02:00
57aac04480 Merge pull request #63906 from Faless/fix/4.x_warnings 2022-08-04 15:16:00 +02:00
6f02183f8c [Core] Use std type traits to check operations triviality. 2022-08-04 14:05:17 +02:00
c717d5c64b Arrays: Zero new items of trivial types on resize() (bindings only)
This is not enabled by default in the core version for performance reasons,
as Vector/CowData are used in critical code paths where not zero'ing memory
which is going to be set later on can be important.

But for bindings / the scripting API, we make zero the new items by default
(which already happened for built types like Vector3, etc., but not for
trivial types like int, float).

Fixes #43033.

Co-authored-by: David Hoppenbrouwers <david@salt-inc.org>
2022-08-04 13:35:37 +02:00
380a53f02f Add search methods for packed arrays
* count()
* find()
* rfind()
2022-05-07 20:16:11 +08:00
6dfcfecd3d Remove get_data() from CowData 2022-04-09 21:25:31 +02:00
fe52458154 Update copyright statements to 2022
Happy new year to the wonderful Godot community!
2022-01-03 21:27:34 +01:00
e078f970db Rename remove() to remove_at() when removing by index 2021-11-23 18:58:57 -07:00
abef2b7194 Fix placement new on zero-sized region warning on GCC 11.1
On latest (11.1 as of this commit) GCC, the following warning is
continuously issued during build:
warning: placement new constructing an object of type
'SafeNumeric<unsigned int>' and size '4' in a region of type
'uint32_t*' {aka 'unsigned int*'} and size '0' [-Wplacement-new=]

This happens because on 98ceb60eb4 the new operator override used
was dropped and replaced with standard placement new. GCC sees the
subtraction from the pointer and complains as it thinks that the
SafeNumeric is placed outside an allocation, not knowing that the
address requested is already inside one.

After suggestions, the false positive is silenced, with no other
changes.
2021-09-15 00:07:21 +03:00
98ceb60eb4 Refactors the memnew_placement.
With this commit the macro `memnew_placement` uses the standard memory
placement syntax: `new (mem) TheClass()`, and removes the outdated and
not used syntax:
```
_ALWAYS_INLINE_ void *operator new(size_t p_size, void *p_pointer, size_t check, const char *p_description) {
```

Thanks to this change, the function `memnew_placement` call is compatible with
any class, and can also initialize classes with non-empty constructor:
```
// This is valid, like before.
memnew_placement(mem, Variant);

// This works too:
memnew_placement(mem, Variant(123));
```
2021-08-13 10:18:34 +02:00
bb6ece1450 Change CRASH_COND to ERR_FAIL in Cowdata::set 2021-02-24 21:36:08 +01:00
e3ec31f999 Improve robustness of atomics
And fix increment in `CowData` not being conditional anymore after the recent changes.

Co-authored-by: Hein-Pieter van Braam-Stewart <hp@tmm.cx>
2021-02-19 03:05:56 +01:00
8e128726f0 Modernize atomics
- Based on C++11's `atomic`
- Reworked `SafeRefCount` (based on the rewrite by @hpvb)
- Replaced free atomic functions by the new `SafeNumeric<T>`
- Replaced wrong cases of `volatile bool` by the new `SafeFlag`
- Platform-specific implementations no longer needed

Co-authored-by: Hein-Pieter van Braam-Stewart <hp@tmm.cx>
2021-02-18 17:12:46 +01:00