mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-25 09:39:52 +08:00
Remove the intern'd strings component
Intern'd strings were intended to be "shared" to reduce memory usage but this optimization doesn't carry its weight. Remove it. No functional change expected.
This commit is contained in:
parent
082f074bb1
commit
2a0e0d6721
|
@ -106,7 +106,7 @@ set(FISH_SRCS
|
|||
src/expand.cpp src/fallback.cpp src/fd_monitor.cpp src/fish_version.cpp
|
||||
src/flog.cpp src/function.cpp src/future_feature_flags.cpp src/highlight.cpp
|
||||
src/history.cpp src/history_file.cpp src/input.cpp src/input_common.cpp
|
||||
src/intern.cpp src/io.cpp src/iothread.cpp src/job_group.cpp src/kill.cpp
|
||||
src/io.cpp src/iothread.cpp src/job_group.cpp src/kill.cpp
|
||||
src/null_terminated_array.cpp src/operation_context.cpp src/output.cpp
|
||||
src/pager.cpp src/parse_execution.cpp src/parse_tree.cpp src/parse_util.cpp
|
||||
src/parser.cpp src/parser_keywords.cpp src/path.cpp src/postfork.cpp
|
||||
|
|
|
@ -71,7 +71,6 @@
|
|||
#include "exec.h"
|
||||
#include "fallback.h" // IWYU pragma: keep
|
||||
#include "flog.h"
|
||||
#include "intern.h"
|
||||
#include "io.h"
|
||||
#include "parse_constants.h"
|
||||
#include "parse_util.h"
|
||||
|
@ -430,13 +429,6 @@ static const builtin_data_t *builtin_lookup(const wcstring &name) {
|
|||
return get_by_sorted_name(name.c_str(), builtin_datas);
|
||||
}
|
||||
|
||||
/// Initialize builtin data.
|
||||
void builtin_init() {
|
||||
for (const auto &builtin_data : builtin_datas) {
|
||||
intern_static(builtin_data.name);
|
||||
}
|
||||
}
|
||||
|
||||
/// Is there a builtin command with the given name?
|
||||
bool builtin_exists(const wcstring &cmd) { return static_cast<bool>(builtin_lookup(cmd)); }
|
||||
|
||||
|
|
|
@ -78,7 +78,6 @@ struct builtin_data_t {
|
|||
/// The send stuff to foreground message.
|
||||
#define FG_MSG _(L"Send job %d (%ls) to foreground\n")
|
||||
|
||||
void builtin_init();
|
||||
bool builtin_exists(const wcstring &cmd);
|
||||
|
||||
proc_status_t builtin_run(parser_t &parser, const wcstring_list_t &argv, io_streams_t &streams);
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include "../common.h"
|
||||
#include "../env.h"
|
||||
#include "../fallback.h" // IWYU pragma: keep
|
||||
#include "../intern.h"
|
||||
#include "../io.h"
|
||||
#include "../parser.h"
|
||||
#include "../proc.h"
|
||||
|
|
|
@ -48,7 +48,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|||
#include "function.h"
|
||||
#include "future_feature_flags.h"
|
||||
#include "history.h"
|
||||
#include "intern.h"
|
||||
#include "io.h"
|
||||
#include "parse_util.h"
|
||||
#include "parser.h"
|
||||
|
@ -502,7 +501,6 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
mutable_fish_features().set_from_string(opts.features);
|
||||
proc_init();
|
||||
builtin_init();
|
||||
misc_init();
|
||||
reader_init();
|
||||
|
||||
|
|
|
@ -7083,7 +7083,6 @@ int main(int argc, char **argv) {
|
|||
set_main_thread();
|
||||
setup_fork_guards();
|
||||
proc_init();
|
||||
builtin_init();
|
||||
env_init();
|
||||
misc_init();
|
||||
reader_init();
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "exec.h"
|
||||
#include "fallback.h" // IWYU pragma: keep
|
||||
#include "function.h"
|
||||
#include "intern.h"
|
||||
#include "parser.h"
|
||||
#include "parser_keywords.h"
|
||||
#include "reader.h"
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
// Library for pooling common strings.
|
||||
#include "config.h" // IWYU pragma: keep
|
||||
|
||||
#include "intern.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cwchar>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "common.h"
|
||||
#include "fallback.h" // IWYU pragma: keep
|
||||
|
||||
static bool string_less_than_string(const wchar_t *a, const wchar_t *b) {
|
||||
return std::wcscmp(a, b) < 0;
|
||||
}
|
||||
|
||||
/// The table of intern'd strings.
|
||||
owning_lock<std::vector<const wchar_t *>> string_table;
|
||||
|
||||
static const wchar_t *intern_with_dup(const wchar_t *in, bool dup) {
|
||||
if (!in) return nullptr;
|
||||
|
||||
auto table = string_table.acquire();
|
||||
|
||||
const wchar_t *result;
|
||||
auto iter = std::lower_bound(table->begin(), table->end(), in, string_less_than_string);
|
||||
if (iter != table->end() && std::wcscmp(*iter, in) == 0) {
|
||||
result = *iter;
|
||||
} else {
|
||||
result = dup ? wcsdup(in) : in;
|
||||
table->insert(iter, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const wchar_t *intern(const wchar_t *in) { return intern_with_dup(in, true); }
|
||||
|
||||
const wchar_t *intern_static(const wchar_t *in) { return intern_with_dup(in, false); }
|
17
src/intern.h
17
src/intern.h
|
@ -1,17 +0,0 @@
|
|||
// Library for pooling common strings.
|
||||
#ifndef FISH_INTERN_H
|
||||
#define FISH_INTERN_H
|
||||
|
||||
/// Return an identical copy of the specified string from a pool of unique strings. If the string
|
||||
/// was not in the pool, add a copy.
|
||||
///
|
||||
/// \param in the string to return an interned copy of.
|
||||
const wchar_t *intern(const wchar_t *in);
|
||||
|
||||
/// Insert the specified string literal into the pool of unique strings. The string will not first
|
||||
/// be copied, and it will not be free'd on exit.
|
||||
///
|
||||
/// \param in the string to add to the interned pool
|
||||
const wchar_t *intern_static(const wchar_t *in);
|
||||
|
||||
#endif
|
|
@ -19,7 +19,6 @@
|
|||
#include "fallback.h" // IWYU pragma: keep
|
||||
#include "flog.h"
|
||||
#include "function.h"
|
||||
#include "intern.h"
|
||||
#include "job_group.h"
|
||||
#include "parse_constants.h"
|
||||
#include "parse_execution.h"
|
||||
|
|
|
@ -61,7 +61,6 @@
|
|||
#include "history.h"
|
||||
#include "input.h"
|
||||
#include "input_common.h"
|
||||
#include "intern.h"
|
||||
#include "io.h"
|
||||
#include "iothread.h"
|
||||
#include "kill.h"
|
||||
|
|
Loading…
Reference in New Issue
Block a user