Commit Graph

677 Commits

Author SHA1 Message Date
Andreas Kling
f27a646bf5 AK: Don't bring in LibBareMetal's kstdio.h in userspace 2020-02-15 19:18:56 +01:00
Andreas Kling
b515ea454f AK: Make sure that Weakable always has the same memory layout
Weakable objects ended up with differing memory layouts in some ports
since they don't build with the DEBUG macro defined.

Instead of forcing ports to define DEBUG, just put this behind a custom
WEAKABLE_DEBUG macro and leave it always-on for now.
2020-02-15 14:49:57 +01:00
Andreas Kling
175cd4d9c2 AK: Fix broken #include statement 2020-02-15 13:28:33 +01:00
Andreas Kling
dc417ada6d AK: Add BufferStream to Forward.h 2020-02-15 12:10:48 +01:00
Shannon Booth
9920d17342 AK: Add String starts_with(char) & ends_with(char)
This is simply meant to be a more efficient implementation in the
case that we only need to check a single character.
2020-02-15 11:40:05 +01:00
Andreas Kling
d85b09893d AK: Add Utf8View to Forward.h 2020-02-14 23:31:18 +01:00
Andreas Kling
22b41a0fa3 AK: Add LogStream and DebugLogStream to Forward.h 2020-02-14 23:31:18 +01:00
Andreas Kling
184475d45a AK: Add SharedBuffer to Forward.h 2020-02-14 23:31:18 +01:00
Andreas Kling
8f7333f080 LibCore: Add a forward declaration header
This patch adds <LibCore/Forward.h> and uses it in various places to
shrink the header dependency graph.
2020-02-14 23:31:18 +01:00
Andreas Kling
3bbf4610d2 AK: Add a forward declaration header
You can now #include <AK/Forward.h> to get most of the AK types as
forward declarations.

Header dependency explosion is one of the main contributors to compile
times at the moment, so this is a step towards smaller include graphs.
2020-02-14 23:31:18 +01:00
Andreas Kling
3e486f75ff AK: Move escape_html_entities() from LibHTML to AK
This sort of thing can be useful to things that don't want to link with
all of LibHTML.
2020-02-13 08:46:00 +01:00
Andreas Kling
6cbd72f54f AK: Remove bitrotted Traits::dump() mechanism
This was only used by HashTable::dump() which I used when doing the
first HashTable implementation. Removing this allows us to also remove
most includes of <AK/kstdio.h>.
2020-02-10 11:55:34 +01:00
Liav A
8bdb08c354 AK: Apply changes for the Bootstrapper environment 2020-02-09 19:38:17 +01:00
Andreas Kling
80b1af2352 AK: Make StringBuilder::to_string() non-destructive
This was an artifact of an earlier design of StringBuilder where I had
attempted to preserve the same allocation from build to final String.
2020-02-09 14:15:55 +01:00
Andreas Kling
745ea2a0ef AK: Add JsonObjectSerializer::add(key, bool) overload
Without this, bools will get implicitly converted to integers, which is
usually not what we want.
2020-02-08 02:48:27 +01:00
Andreas Kling
a7e72f78cd AK: Make PrintfImplementation treat %lld as 64-bit 2020-02-08 01:43:05 +01:00
Andreas Kling
28a5e33134 AK: Add LogStream overloads for long and long long 2020-02-08 01:41:43 +01:00
Andreas Kling
9afda55d73 AK: Add some missing "inline" keywords in JsonObject.h 2020-02-06 19:32:17 +01:00
Andreas Kling
939a605334 AK: Add missing StdLibExtras.h include in Optional.h 2020-02-06 11:55:19 +01:00
Andreas Kling
0cff25ac78 AK+IPCCompiler: Get rid of BufferStream overloads for size_t
Since BufferStream is about creating specific binary stream formats,
let's not have a flaky type like size_t in there. Instead, clients of
BufferStream can cast their size_t to the binary size they want to use.

Account for this in IPCCompiler by making String lengths always 32-bit.
2020-02-05 19:13:44 +01:00
Andreas Kling
be0034d2ca AK: Break LogStream::operator<< overloads into i/l/ll and u/ul/ull 2020-02-05 19:13:44 +01:00
Andreas Kling
90b1dafeff AK: Break String::number() overloads into i/l/ll and u/ul/ull
Now that we're trying to be more portable, we can't only rely on using
i32/u32 and i64/u64 since different systems have different combinations
of int/long/long long and unsigned/unsigned long/unsigned long long.
2020-02-05 19:13:44 +01:00
joshua stein
0c4c5b5eb7 AK: Support 64-bit integers in BufferStream 2020-02-05 18:39:45 +01:00
joshua stein
dc93ed4368 AK: Add support for 64-bit size_t 2020-02-05 18:39:45 +01:00
Andreas Kling
c600280dde AK: The <cxxabi.h> header is not available during Toolchain build
This will need some refinement, but basically since we build LibC
during the toolchain build, we don't have libstdc++ headers yet.
2020-02-03 06:27:54 +01:00
Andreas Kling
8ccf0e16a9 AK: Turn demangling back on for userspace
This didn't work at some point, but now it apparently works again. :^)
2020-02-02 20:15:58 +01:00
Andreas Kling
ab57db2bf1 AK: #ifdef out the contents of SharedBuffer on other platforms 2020-02-01 20:18:53 +01:00
Andreas Kling
268000e166 AK: Always inline StringView(const char*)
Also use strlen() instead of manually walking the string. This allows
GCC to optimize away the strlen() entirely for string literals. :^)
2020-02-01 13:54:13 +01:00
Andreas Kling
276b6a4372 AK: Add some integer overloads to JsonObjectSerializer
This avoids constructing a temporary JsonValue just to append an int.
2020-02-01 10:56:17 +01:00
William McPherson
ddefb95b21 AK: Add FixedArray::data() 2020-01-31 13:13:04 +01:00
Marios Prokopakis
da296f5865 Ext2FS: allocate_blocks allocates contiguous blocks (#1095)
This implementation uses the new helper method of Bitmap called
find_longest_range_of_unset_bits. This method looks for the biggest 
range of contiguous bits unset in the bitmap and returns the start of
the range back to the caller.
2020-01-26 09:48:24 +01:00
Andreas Kling
603bf6fb4a Build: Remove -fno-sized-deallocation -Wno-sized-deallocation
Add sized variants of the global operator delete functions so we don't
have to use these GCC options anymore.
2020-01-25 16:59:21 +01:00
Andreas Kling
003d52ce6e AK: Vector::is_null() should always return false
This is only used by the somewhat dubious templated String::copy().
An empty Vector should generate an empty String when copied, never
a null String.
2020-01-25 12:14:59 +01:00
Andreas Kling
3f52cee595 AK: Assert if trying to create a WeakPtr to an object being destroyed
Trying to make_weak_ptr() on something that has begun destruction is
very unlikely to be what you want. Let's assert if that scenario comes
up so we can catch it immediately.
2020-01-25 10:34:32 +01:00
Sergey Bugaev
c0b32f7b76 Meta: Claim copyright for files created by me
This changes copyright holder to myself for the source code files that I've
created or have (almost) completely rewritten. Not included are the files
that were significantly changed by others even though it was me who originally
created them (think HtmlView), or the many other files I've contributed code to.
2020-01-24 15:15:16 +01:00
Andreas Kling
ca413a5b50 AK: Use swap-based assignment in OwnPtr
Also provide a specialized swap(OwnPtr, OwnPtr) that allows swapping
an OwnPtr with itself.
2020-01-24 09:35:55 +01:00
Andreas Kling
3de5439579 AK: Let's call decrementing reference counts "unref" instead of "deref"
It always bothered me that we're using the overloaded "dereference"
term for this. Let's call it "unreference" instead. :^)
2020-01-23 15:14:21 +01:00
Andreas Kling
d66bbc21ce AK: Unbreak FileSystemPath after String::split() changes
FileSystemPath(".") should not have a title(). This was caught by the
unit test for FileSystemPath, yay! :^)
2020-01-22 22:35:12 +01:00
Sergey Bugaev
6a64077ed7 AK: Also add a keep_empty argument to String::split[_limit]()
Just like String[View]::split_view() has already.
2020-01-22 21:22:23 +01:00
Andreas Kling
f38cfb3562 Kernel: Tidy up debug logging a little bit
When using dbg() in the kernel, the output is automatically prefixed
with [Process(PID:TID)]. This makes it a lot easier to understand which
thread is generating the output.

This patch also cleans up some common logging messages and removes the
now-unnecessary "dbg() << *current << ..." pattern.
2020-01-21 16:16:20 +01:00
Andreas Kling
2309029cb4 AK: Allow clamp() with min==max 2020-01-20 13:49:05 +01:00
Andreas Kling
e07b34b9b8 Kernel+AK: Add/fix uintptr_t and intptr_t definitions
We should move towards using uintptr_t instead of u32 for pointers
everywhere, to prepare for an eventual 64-bit port.
2020-01-20 13:13:03 +01:00
Shannon Booth
de74458f13 AK: Add clamp() function
This function can be used to more cleanly write the common operation of
clamping a value between two values.
2020-01-20 10:35:12 +01:00
Andreas Kling
d394267f50 AK: Add NonnullOwnPtr::swap() as well for symmetry 2020-01-19 16:03:57 +01:00
Andreas Kling
ad3f931707 Kernel: Optimize VM range deallocation a bit
Previously, when deallocating a range of VM, we would sort and merge
the range list. This was quite slow for large processes.

This patch optimizes VM deallocation in the following ways:

- Use binary search instead of linear scan to find the place to insert
  the deallocated range.

- Insert at the right place immediately, removing the need to sort.

- Merge the inserted range with any adjacent range(s) in-line instead
  of doing a separate merge pass into a list copy.

- Add Traits<Range> to inform Vector that Range objects are trivial
  and can be moved using memmove().

I've also added an assertion that deallocated ranges are actually part
of the RangeAllocator's initial address range.

I've benchmarked this using g++ to compile Kernel/Process.cpp.
With these changes, compilation goes from ~41 sec to ~35 sec.
2020-01-19 13:29:59 +01:00
Andreas Kling
502626eecb AK: Teach Vector::insert() to use memmove() for trivial types 2020-01-19 12:15:43 +01:00
Andreas Kling
109727082c AK: Support '+' qualifier in printf() to force sign for positive %d's 2020-01-19 11:00:02 +01:00
Andreas Kling
39b3c0ef7e AK: Make it possible to swap() a NonnullRefPtr with itself
The generic swap() is not able to swap a NonnullRefPtr with itself,
due to its use of a temporary and NonnullRefPtr asserting when trying
to move() from an already move()'d instance.
2020-01-19 10:33:26 +01:00
Andreas Kling
604c5cb98e AK: Add some missing "inline" keywords in StdLibExtras.h 2020-01-19 10:33:26 +01:00
Andreas Kling
7ea264a660 AK: NonnullRefPtr should allow assigning owner to ownee
Given the following situation:

    struct Object : public RefCounted<Object> {
        RefPtr<Object> parent;
    }

    NonnullRefPtr<Object> object = get_some_object();
    object = *object->parent;

We would previously crash if 'object' was the only strongly referencing
pointer to 'parent'. This happened because NonnullRefPtr would unref
the outgoing pointee before reffing the incoming pointee.

This patch fixes that by implementing NonnullRefPtr assignments using
pointer swaps, just like RefPtr already did.
2020-01-18 14:40:04 +01:00