Browse Source

Everywhere: Use default StringView constructor over nullptr

While null StringViews are just as bad, these prevent the removal of
StringView(char const*) as that constructor accepts a nullptr.

No functional changes.
sin-ack 3 years ago
parent
commit
fbc771efe9

+ 2 - 2
Kernel/Interrupts/APIC.cpp

@@ -81,7 +81,7 @@ public:
 
 
     virtual HandlerType type() const override { return HandlerType::IRQHandler; }
     virtual HandlerType type() const override { return HandlerType::IRQHandler; }
     virtual StringView purpose() const override { return "IPI Handler"sv; }
     virtual StringView purpose() const override { return "IPI Handler"sv; }
-    virtual StringView controller() const override { return nullptr; }
+    virtual StringView controller() const override { return {}; }
 
 
     virtual size_t sharing_devices_count() const override { return 0; }
     virtual size_t sharing_devices_count() const override { return 0; }
     virtual bool is_shared_handler() const override { return false; }
     virtual bool is_shared_handler() const override { return false; }
@@ -112,7 +112,7 @@ public:
 
 
     virtual HandlerType type() const override { return HandlerType::IRQHandler; }
     virtual HandlerType type() const override { return HandlerType::IRQHandler; }
     virtual StringView purpose() const override { return "SMP Error Handler"sv; }
     virtual StringView purpose() const override { return "SMP Error Handler"sv; }
-    virtual StringView controller() const override { return nullptr; }
+    virtual StringView controller() const override { return {}; }
 
 
     virtual size_t sharing_devices_count() const override { return 0; }
     virtual size_t sharing_devices_count() const override { return 0; }
     virtual bool is_shared_handler() const override { return false; }
     virtual bool is_shared_handler() const override { return false; }

+ 1 - 1
Kernel/PerformanceEventBuffer.cpp

@@ -348,7 +348,7 @@ ErrorOr<void> PerformanceEventBuffer::add_process(Process const& process, Proces
     ErrorOr<void> result;
     ErrorOr<void> result;
     process.for_each_thread([&](auto& thread) {
     process.for_each_thread([&](auto& thread) {
         result = append_with_ip_and_bp(process.pid(), thread.tid().value(),
         result = append_with_ip_and_bp(process.pid(), thread.tid().value(),
-            0, 0, PERF_EVENT_THREAD_CREATE, 0, 0, 0, nullptr);
+            0, 0, PERF_EVENT_THREAD_CREATE, 0, 0, 0, {});
         return result.is_error() ? IterationDecision::Break : IterationDecision::Continue;
         return result.is_error() ? IterationDecision::Break : IterationDecision::Continue;
     });
     });
     TRY(result);
     TRY(result);

+ 11 - 11
Kernel/PerformanceManager.h

@@ -34,7 +34,7 @@ public:
         if (g_profiling_all_threads) {
         if (g_profiling_all_threads) {
             VERIFY(g_global_perf_events);
             VERIFY(g_global_perf_events);
             [[maybe_unused]] auto rc = g_global_perf_events->append_with_ip_and_bp(
             [[maybe_unused]] auto rc = g_global_perf_events->append_with_ip_and_bp(
-                process.pid(), 0, 0, 0, PERF_EVENT_PROCESS_EXIT, 0, 0, 0, nullptr);
+                process.pid(), 0, 0, 0, PERF_EVENT_PROCESS_EXIT, 0, 0, 0, {});
         }
         }
     }
     }
 
 
@@ -43,7 +43,7 @@ public:
         if (thread.is_profiling_suppressed())
         if (thread.is_profiling_suppressed())
             return;
             return;
         if (auto* event_buffer = thread.process().current_perf_events_buffer()) {
         if (auto* event_buffer = thread.process().current_perf_events_buffer()) {
-            [[maybe_unused]] auto rc = event_buffer->append(PERF_EVENT_THREAD_CREATE, thread.tid().value(), 0, nullptr, &thread);
+            [[maybe_unused]] auto rc = event_buffer->append(PERF_EVENT_THREAD_CREATE, thread.tid().value(), 0, {}, &thread);
         }
         }
     }
     }
 
 
@@ -52,7 +52,7 @@ public:
         // As an exception this doesn't check whether profiling is suppressed for
         // As an exception this doesn't check whether profiling is suppressed for
         // the thread so we can record the thread_exit event anyway.
         // the thread so we can record the thread_exit event anyway.
         if (auto* event_buffer = thread.process().current_perf_events_buffer()) {
         if (auto* event_buffer = thread.process().current_perf_events_buffer()) {
-            [[maybe_unused]] auto rc = event_buffer->append(PERF_EVENT_THREAD_EXIT, thread.tid().value(), 0, nullptr, &thread);
+            [[maybe_unused]] auto rc = event_buffer->append(PERF_EVENT_THREAD_EXIT, thread.tid().value(), 0, {}, &thread);
         }
         }
     }
     }
 
 
@@ -62,7 +62,7 @@ public:
             return;
             return;
         if (auto* event_buffer = current_thread.process().current_perf_events_buffer()) {
         if (auto* event_buffer = current_thread.process().current_perf_events_buffer()) {
             [[maybe_unused]] auto rc = event_buffer->append_with_ip_and_bp(
             [[maybe_unused]] auto rc = event_buffer->append_with_ip_and_bp(
-                current_thread.pid(), current_thread.tid(), regs, PERF_EVENT_SAMPLE, lost_time, 0, 0, nullptr);
+                current_thread.pid(), current_thread.tid(), regs, PERF_EVENT_SAMPLE, lost_time, 0, 0, {});
         }
         }
     }
     }
 
 
@@ -76,7 +76,7 @@ public:
     inline static void add_unmap_perf_event(Process& current_process, Memory::VirtualRange const& region)
     inline static void add_unmap_perf_event(Process& current_process, Memory::VirtualRange const& region)
     {
     {
         if (auto* event_buffer = current_process.current_perf_events_buffer()) {
         if (auto* event_buffer = current_process.current_perf_events_buffer()) {
-            [[maybe_unused]] auto res = event_buffer->append(PERF_EVENT_MUNMAP, region.base().get(), region.size(), nullptr);
+            [[maybe_unused]] auto res = event_buffer->append(PERF_EVENT_MUNMAP, region.base().get(), region.size(), {});
         }
         }
     }
     }
 
 
@@ -85,7 +85,7 @@ public:
         if (current_thread.is_profiling_suppressed())
         if (current_thread.is_profiling_suppressed())
             return;
             return;
         if (auto* event_buffer = current_thread.process().current_perf_events_buffer()) {
         if (auto* event_buffer = current_thread.process().current_perf_events_buffer()) {
-            [[maybe_unused]] auto res = event_buffer->append(PERF_EVENT_CONTEXT_SWITCH, next_thread.pid().value(), next_thread.tid().value(), nullptr);
+            [[maybe_unused]] auto res = event_buffer->append(PERF_EVENT_CONTEXT_SWITCH, next_thread.pid().value(), next_thread.tid().value(), {});
         }
         }
     }
     }
 
 
@@ -94,7 +94,7 @@ public:
         if (current_thread.is_profiling_suppressed())
         if (current_thread.is_profiling_suppressed())
             return;
             return;
         if (auto* event_buffer = current_thread.process().current_perf_events_buffer()) {
         if (auto* event_buffer = current_thread.process().current_perf_events_buffer()) {
-            [[maybe_unused]] auto res = event_buffer->append(PERF_EVENT_KMALLOC, size, ptr, nullptr);
+            [[maybe_unused]] auto res = event_buffer->append(PERF_EVENT_KMALLOC, size, ptr, {});
         }
         }
     }
     }
 
 
@@ -103,7 +103,7 @@ public:
         if (current_thread.is_profiling_suppressed())
         if (current_thread.is_profiling_suppressed())
             return;
             return;
         if (auto* event_buffer = current_thread.process().current_perf_events_buffer()) {
         if (auto* event_buffer = current_thread.process().current_perf_events_buffer()) {
-            [[maybe_unused]] auto res = event_buffer->append(PERF_EVENT_KFREE, size, ptr, nullptr);
+            [[maybe_unused]] auto res = event_buffer->append(PERF_EVENT_KFREE, size, ptr, {});
         }
         }
     }
     }
 
 
@@ -113,7 +113,7 @@ public:
             return;
             return;
         if (auto* event_buffer = thread.process().current_perf_events_buffer()) {
         if (auto* event_buffer = thread.process().current_perf_events_buffer()) {
             [[maybe_unused]] auto rc = event_buffer->append_with_ip_and_bp(
             [[maybe_unused]] auto rc = event_buffer->append_with_ip_and_bp(
-                thread.pid(), thread.tid(), regs, PERF_EVENT_PAGE_FAULT, 0, 0, 0, nullptr);
+                thread.pid(), thread.tid(), regs, PERF_EVENT_PAGE_FAULT, 0, 0, 0, {});
         }
         }
     }
     }
 
 
@@ -123,7 +123,7 @@ public:
             return;
             return;
         if (auto* event_buffer = thread.process().current_perf_events_buffer()) {
         if (auto* event_buffer = thread.process().current_perf_events_buffer()) {
             [[maybe_unused]] auto rc = event_buffer->append_with_ip_and_bp(
             [[maybe_unused]] auto rc = event_buffer->append_with_ip_and_bp(
-                thread.pid(), thread.tid(), regs, PERF_EVENT_SYSCALL, 0, 0, 0, nullptr);
+                thread.pid(), thread.tid(), regs, PERF_EVENT_SYSCALL, 0, 0, 0, {});
         }
         }
     }
     }
 
 
@@ -158,7 +158,7 @@ public:
             filepath_string_index = registered_result.value();
             filepath_string_index = registered_result.value();
         }
         }
 
 
-        [[maybe_unused]] auto rc = event_buffer->append(PERF_EVENT_READ, fd, size, 0, &thread, filepath_string_index, start_timestamp, result); // wrong arguments
+        [[maybe_unused]] auto rc = event_buffer->append(PERF_EVENT_READ, fd, size, {}, &thread, filepath_string_index, start_timestamp, result); // wrong arguments
     }
     }
 
 
     inline static void timer_tick(RegisterState const& regs)
     inline static void timer_tick(RegisterState const& regs)

+ 1 - 1
Kernel/Syscalls/perf_event.cpp

@@ -15,7 +15,7 @@ ErrorOr<FlatPtr> Process::sys$perf_event(int type, FlatPtr arg1, FlatPtr arg2)
     auto* events_buffer = current_perf_events_buffer();
     auto* events_buffer = current_perf_events_buffer();
     if (!events_buffer)
     if (!events_buffer)
         return 0;
         return 0;
-    TRY(events_buffer->append(type, arg1, arg2, nullptr));
+    TRY(events_buffer->append(type, arg1, arg2, {}));
     return 0;
     return 0;
 }
 }
 
 

+ 1 - 1
Kernel/Time/HardwareTimer.h

@@ -133,7 +133,7 @@ public:
     virtual bool is_shared_handler() const override { return false; }
     virtual bool is_shared_handler() const override { return false; }
     virtual bool is_sharing_with_others() const override { return false; }
     virtual bool is_sharing_with_others() const override { return false; }
     virtual HandlerType type() const override { return HandlerType::IRQHandler; }
     virtual HandlerType type() const override { return HandlerType::IRQHandler; }
-    virtual StringView controller() const override { return nullptr; }
+    virtual StringView controller() const override { return {}; }
     virtual bool eoi() override;
     virtual bool eoi() override;
 
 
     virtual u32 frequency() const override { return (u32)m_frequency; }
     virtual u32 frequency() const override { return (u32)m_frequency; }

+ 2 - 2
Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/main.cpp

@@ -32,8 +32,8 @@ void generate_iterator_implementation(IDL::Interface const&);
 int main(int argc, char** argv)
 int main(int argc, char** argv)
 {
 {
     Core::ArgsParser args_parser;
     Core::ArgsParser args_parser;
-    StringView path = nullptr;
-    StringView import_base_path = nullptr;
+    StringView path;
+    StringView import_base_path;
     bool header_mode = false;
     bool header_mode = false;
     bool implementation_mode = false;
     bool implementation_mode = false;
     bool constructor_header_mode = false;
     bool constructor_header_mode = false;

+ 1 - 1
Userland/Libraries/LibELF/Image.cpp

@@ -163,7 +163,7 @@ StringView Image::table_string(unsigned table_index, unsigned offset) const
     VERIFY(m_valid);
     VERIFY(m_valid);
     auto& sh = section_header(table_index);
     auto& sh = section_header(table_index);
     if (sh.sh_type != SHT_STRTAB)
     if (sh.sh_type != SHT_STRTAB)
-        return nullptr;
+        return {};
     size_t computed_offset = sh.sh_offset + offset;
     size_t computed_offset = sh.sh_offset + offset;
     if (computed_offset >= m_size) {
     if (computed_offset >= m_size) {
         if (m_verbose_logging)
         if (m_verbose_logging)

+ 1 - 1
Userland/Libraries/LibJS/Lexer.cpp

@@ -23,7 +23,7 @@ HashMap<char, TokenType> Lexer::s_single_char_tokens;
 
 
 Lexer::Lexer(StringView source, StringView filename, size_t line_number, size_t line_column)
 Lexer::Lexer(StringView source, StringView filename, size_t line_number, size_t line_column)
     : m_source(source)
     : m_source(source)
-    , m_current_token(TokenType::Eof, {}, StringView(nullptr), StringView(nullptr), filename, 0, 0, 0)
+    , m_current_token(TokenType::Eof, {}, {}, {}, filename, 0, 0, 0)
     , m_filename(filename)
     , m_filename(filename)
     , m_line_number(line_number)
     , m_line_number(line_number)
     , m_line_column(line_column)
     , m_line_column(line_column)

+ 1 - 1
Userland/Libraries/LibRegex/RegexByteCode.cpp

@@ -855,7 +855,7 @@ Vector<String> OpCode_Compare::variable_arguments_to_string(Optional<MatchInput>
     Vector<String> result;
     Vector<String> result;
 
 
     size_t offset { state().instruction_position + 3 };
     size_t offset { state().instruction_position + 3 };
-    RegexStringView view = ((input.has_value()) ? input.value().view : nullptr);
+    RegexStringView view = ((input.has_value()) ? input.value().view : StringView {});
 
 
     for (size_t i = 0; i < arguments_count(); ++i) {
     for (size_t i = 0; i < arguments_count(); ++i) {
         auto compare_type = (CharacterCompareType)m_bytecode->at(offset++);
         auto compare_type = (CharacterCompareType)m_bytecode->at(offset++);

+ 3 - 3
Userland/Libraries/LibRegex/RegexLexer.cpp

@@ -32,7 +32,7 @@ char const* Token::name() const
 }
 }
 
 
 Lexer::Lexer()
 Lexer::Lexer()
-    : GenericLexer(StringView { nullptr })
+    : GenericLexer(StringView {})
 {
 {
 }
 }
 
 
@@ -62,7 +62,7 @@ char Lexer::consume()
 void Lexer::reset()
 void Lexer::reset()
 {
 {
     m_index = 0;
     m_index = 0;
-    m_current_token = { TokenType::Eof, 0, StringView(nullptr) };
+    m_current_token = { TokenType::Eof, 0, {} };
     m_previous_position = 0;
     m_previous_position = 0;
 }
 }
 
 
@@ -178,7 +178,7 @@ Token Lexer::next()
         return emit_token(TokenType::Char);
         return emit_token(TokenType::Char);
     }
     }
 
 
-    return Token(TokenType::Eof, m_index, nullptr);
+    return Token(TokenType::Eof, m_index, {});
 }
 }
 
 
 }
 }

+ 2 - 2
Userland/Libraries/LibRegex/RegexLexer.h

@@ -61,7 +61,7 @@ public:
 private:
 private:
     TokenType m_type { TokenType::Eof };
     TokenType m_type { TokenType::Eof };
     size_t m_position { 0 };
     size_t m_position { 0 };
-    StringView m_value { nullptr };
+    StringView m_value {};
 };
 };
 
 
 class Lexer : public GenericLexer {
 class Lexer : public GenericLexer {
@@ -77,7 +77,7 @@ public:
 
 
 private:
 private:
     size_t m_previous_position { 0 };
     size_t m_previous_position { 0 };
-    Token m_current_token { TokenType::Eof, 0, StringView(nullptr) };
+    Token m_current_token { TokenType::Eof, 0, {} };
 };
 };
 
 
 }
 }

+ 1 - 1
Userland/Libraries/LibRegex/RegexParser.cpp

@@ -169,7 +169,7 @@ ALWAYS_INLINE void Parser::reset()
     m_parser_state.lexer.reset();
     m_parser_state.lexer.reset();
     m_parser_state.current_token = m_parser_state.lexer.next();
     m_parser_state.current_token = m_parser_state.lexer.next();
     m_parser_state.error = Error::NoError;
     m_parser_state.error = Error::NoError;
-    m_parser_state.error_token = { TokenType::Eof, 0, StringView(nullptr) };
+    m_parser_state.error_token = { TokenType::Eof, 0, {} };
     m_parser_state.capture_group_minimum_lengths.clear();
     m_parser_state.capture_group_minimum_lengths.clear();
     m_parser_state.capture_groups_count = 0;
     m_parser_state.capture_groups_count = 0;
     m_parser_state.named_capture_groups_count = 0;
     m_parser_state.named_capture_groups_count = 0;

+ 1 - 1
Userland/Libraries/LibRegex/RegexParser.h

@@ -101,7 +101,7 @@ protected:
         Lexer& lexer;
         Lexer& lexer;
         Token current_token;
         Token current_token;
         Error error = Error::NoError;
         Error error = Error::NoError;
-        Token error_token { TokenType::Eof, 0, StringView(nullptr) };
+        Token error_token { TokenType::Eof, 0, {} };
         ByteCode bytecode;
         ByteCode bytecode;
         size_t capture_groups_count { 0 };
         size_t capture_groups_count { 0 };
         size_t named_capture_groups_count { 0 };
         size_t named_capture_groups_count { 0 };

+ 1 - 1
Userland/Libraries/LibThreading/Thread.h

@@ -34,7 +34,7 @@ public:
     pthread_t tid() const { return m_tid; }
     pthread_t tid() const { return m_tid; }
 
 
 private:
 private:
-    explicit Thread(Function<intptr_t()> action, StringView thread_name = nullptr);
+    explicit Thread(Function<intptr_t()> action, StringView thread_name = {});
     Function<intptr_t()> m_action;
     Function<intptr_t()> m_action;
     pthread_t m_tid { 0 };
     pthread_t m_tid { 0 };
     String m_thread_name;
     String m_thread_name;

+ 1 - 1
Userland/Utilities/paste.cpp

@@ -67,7 +67,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
     auto& clipboard = GUI::Clipboard::the();
     auto& clipboard = GUI::Clipboard::the();
 
 
     if (watch) {
     if (watch) {
-        watch_command.append(nullptr);
+        watch_command.append({});
 
 
         clipboard.on_change = [&](String const&) {
         clipboard.on_change = [&](String const&) {
             // Technically there's a race here...
             // Technically there's a race here...

+ 1 - 1
Userland/Utilities/test.cpp

@@ -516,7 +516,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
         --argc;
         --argc;
         if (StringView { arguments.strings[argc] } != "]")
         if (StringView { arguments.strings[argc] } != "]")
             fatal_error("test invoked as '[' requires a closing bracket ']'");
             fatal_error("test invoked as '[' requires a closing bracket ']'");
-        arguments.strings[argc] = nullptr;
+        arguments.strings[argc] = {};
     }
     }
 
 
     // Exit false when no arguments are given.
     // Exit false when no arguments are given.