mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-12 04:58:57 +00:00
Added a history speed test
Profile driven caching of config directory Style fixes
This commit is contained in:
parent
33fc5c99ea
commit
b9283d48b5
7 changed files with 137 additions and 100 deletions
|
@ -978,6 +978,7 @@ public:
|
|||
static void test_history(void);
|
||||
static void test_history_merge(void);
|
||||
static void test_history_formats(void);
|
||||
static void test_history_speed(void);
|
||||
|
||||
static void test_history_races(void);
|
||||
static void test_history_races_pound_on_history();
|
||||
|
@ -1408,6 +1409,32 @@ void history_tests_t::test_history_formats(void)
|
|||
}
|
||||
}
|
||||
|
||||
void history_tests_t::test_history_speed(void)
|
||||
{
|
||||
say(L"Testing history speed");
|
||||
history_t *hist = new history_t(L"speed_test");
|
||||
wcstring item = L"History Speed Test - X";
|
||||
|
||||
/* Test for 10 seconds */
|
||||
double start = timef();
|
||||
double end = start + 4;
|
||||
double stop = 0;
|
||||
size_t count = 0;
|
||||
for (;;)
|
||||
{
|
||||
item[item.size() - 1] = L'0' + (count % 10);
|
||||
hist->add(item);
|
||||
count++;
|
||||
|
||||
stop = timef();
|
||||
if (stop >= end)
|
||||
break;
|
||||
}
|
||||
printf("%lu items - %.2f msec per item\n", (unsigned long)count, (stop - start) * 1E6 / count);
|
||||
hist->clear();
|
||||
delete hist;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Main test
|
||||
|
@ -1448,6 +1475,7 @@ int main(int argc, char **argv)
|
|||
history_tests_t::test_history_merge();
|
||||
history_tests_t::test_history_races();
|
||||
history_tests_t::test_history_formats();
|
||||
//history_tests_t::test_history_speed();
|
||||
|
||||
say(L"Encountered %d errors in low-level tests", err_count);
|
||||
|
||||
|
|
|
@ -1308,6 +1308,8 @@ bool history_t::save_internal_via_rewrite()
|
|||
{
|
||||
/* We've saved everything, so we have no more unsaved items */
|
||||
this->first_unwritten_new_item_index = new_items.size();
|
||||
|
||||
/* We deleted our deleted items */
|
||||
this->deleted_items.clear();
|
||||
|
||||
/* Our history has been written to the file, so clear our state so we can re-reference the file. */
|
||||
|
@ -1418,7 +1420,7 @@ void history_t::save_internal(bool vacuum)
|
|||
ASSERT_IS_LOCKED(lock);
|
||||
|
||||
/* Nothing to do if there's no new items */
|
||||
if (new_items.empty() && deleted_items.empty())
|
||||
if (first_unwritten_new_item_index >= new_items.size() && deleted_items.empty())
|
||||
return;
|
||||
|
||||
/* Compact our new items so we don't have duplicates */
|
||||
|
|
30
path.cpp
30
path.cpp
|
@ -323,9 +323,9 @@ bool path_can_be_implicit_cd(const wcstring &path, wcstring *out_path, const wch
|
|||
return result;
|
||||
}
|
||||
|
||||
bool path_get_config(wcstring &path)
|
||||
static wcstring path_create_config()
|
||||
{
|
||||
int done = 0;
|
||||
bool done = false;
|
||||
wcstring res;
|
||||
|
||||
const env_var_t xdg_dir = env_get_string(L"XDG_CONFIG_HOME");
|
||||
|
@ -334,7 +334,7 @@ bool path_get_config(wcstring &path)
|
|||
res = xdg_dir + L"/fish";
|
||||
if (!create_directory(res))
|
||||
{
|
||||
done = 1;
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -345,22 +345,26 @@ bool path_get_config(wcstring &path)
|
|||
res = home + L"/.config/fish";
|
||||
if (!create_directory(res))
|
||||
{
|
||||
done = 1;
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (done)
|
||||
if (! done)
|
||||
{
|
||||
path = res;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
debug(0, _(L"Unable to create a configuration directory for fish. Your personal settings will not be saved. Please set the $XDG_CONFIG_HOME variable to a directory where the current user has write access."));
|
||||
return false;
|
||||
}
|
||||
res.clear();
|
||||
|
||||
debug(0, _(L"Unable to create a configuration directory for fish. Your personal settings will not be saved. Please set the $XDG_CONFIG_HOME variable to a directory where the current user has write access."));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Cache the config path */
|
||||
bool path_get_config(wcstring &path)
|
||||
{
|
||||
static const wcstring result = path_create_config();
|
||||
path = result;
|
||||
return ! result.empty();
|
||||
}
|
||||
|
||||
static void replace_all(wcstring &str, const wchar_t *needle, const wchar_t *replacement)
|
||||
|
|
|
@ -768,7 +768,8 @@ static bool test_stuff(screen_t *scr)
|
|||
|
||||
sleep(5);
|
||||
|
||||
for (size_t i=0; i < 1; i++) {
|
||||
for (size_t i=0; i < 1; i++)
|
||||
{
|
||||
writembs(cursor_left);
|
||||
}
|
||||
|
||||
|
@ -780,13 +781,15 @@ static bool test_stuff(screen_t *scr)
|
|||
|
||||
|
||||
|
||||
while (1) {
|
||||
while (1)
|
||||
{
|
||||
int c = getchar();
|
||||
if (c != EOF) break;
|
||||
}
|
||||
|
||||
|
||||
while (1) {
|
||||
while (1)
|
||||
{
|
||||
int c = getchar();
|
||||
if (c != EOF) break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue