aboutsummaryrefslogtreecommitdiffhomepage
path: root/complete.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-07-17 12:47:01 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-07-17 12:47:01 -0700
commitd06d6c69645c4d355772cb19043469328c05ccc5 (patch)
treeba9f91943b94b9b59b3e781580eca5d3230ac493 /complete.cpp
parent977a4477f646e344e66a7b0bc22e2e89b72d20db (diff)
Various changes to reduce fish's compiled code size
OS X release build executable size dropped from 672k to 511k
Diffstat (limited to 'complete.cpp')
-rw-r--r--complete.cpp49
1 files changed, 42 insertions, 7 deletions
diff --git a/complete.cpp b/complete.cpp
index e0ec00b5..4e4d9fc4 100644
--- a/complete.cpp
+++ b/complete.cpp
@@ -251,6 +251,41 @@ const wcstring &completion_entry_t::get_short_opt_str() const {
return short_opt_str;
}
+/* completion_t functions */
+completion_t::completion_t(const wcstring &comp, const wcstring &desc, int flags_val) : completion(comp), description(desc), flags(flags_val)
+{
+}
+
+completion_t::completion_t(const completion_t &him) : completion(him.completion), description(him.description), flags(him.flags)
+{
+}
+
+completion_t &completion_t::operator=(const completion_t &him)
+{
+ if (this != &him)
+ {
+ this->completion = him.completion;
+ this->description = him.description;
+ this->flags = him.flags;
+ }
+ return *this;
+}
+
+wcstring_list_t completions_to_wcstring_list( const std::vector<completion_t> &list )
+{
+ wcstring_list_t strings;
+ strings.reserve(list.size());
+ for (std::vector<completion_t>::const_iterator iter = list.begin(); iter != list.end(); ++iter) {
+ strings.push_back(iter->completion);
+ }
+ return strings;
+}
+
+void sort_completions( std::vector<completion_t> &completions)
+{
+ std::sort(completions.begin(), completions.end());
+}
+
/** Class representing an attempt to compute completions */
class completer_t {
const complete_type_t type;
@@ -347,7 +382,7 @@ void completion_autoload_t::command_removed(const wcstring &cmd) {
Create a new completion entry
*/
-void completion_allocate(std::vector<completion_t> &completions, const wcstring &comp, const wcstring &desc, complete_flags_t flags)
+void append_completion(std::vector<completion_t> &completions, const wcstring &comp, const wcstring &desc, complete_flags_t flags)
{
completions.push_back(completion_t(comp, desc, flags));
}
@@ -1413,7 +1448,7 @@ bool completer_t::complete_param( const wcstring &scmd_orig, const wcstring &spo
completion[0] = o->short_opt;
completion[1] = 0;
- completion_allocate( this->completions, completion, desc, 0 );
+ append_completion( this->completions, completion, desc, 0 );
}
@@ -1465,14 +1500,14 @@ bool completer_t::complete_param( const wcstring &scmd_orig, const wcstring &spo
homebrew getopt-like functions.
*/
wcstring completion = format_string(L"%ls=", whole_opt.c_str()+offset);
- completion_allocate( this->completions,
+ append_completion( this->completions,
completion,
C_(o->desc.c_str()),
flags );
}
- completion_allocate( this->completions,
+ append_completion( this->completions,
whole_opt.c_str() + offset,
C_(o->desc.c_str()),
flags );
@@ -1582,7 +1617,7 @@ bool completer_t::complete_variable(const wcstring &str, int start_offset)
desc = format_string(COMPLETE_VAR_DESC_VAL, value.c_str());
}
- completion_allocate( this->completions, comp.c_str(), desc.c_str(), flags );
+ append_completion( this->completions, comp.c_str(), desc.c_str(), flags );
res =1;
}
@@ -1657,7 +1692,7 @@ bool completer_t::try_complete_user( const wcstring &str )
if( wcsncmp( user_name, pw_name, name_len )==0 )
{
wcstring desc = format_string(COMPLETE_USER_DESC, pw_name);
- completion_allocate( this->completions,
+ append_completion( this->completions,
&pw_name[name_len],
desc,
COMPLETE_NO_SPACE );
@@ -1669,7 +1704,7 @@ bool completer_t::try_complete_user( const wcstring &str )
wcstring name = format_string(L"~%ls", pw_name);
wcstring desc = format_string(COMPLETE_USER_DESC, pw_name);
- completion_allocate( this->completions,
+ append_completion( this->completions,
name,
desc,
COMPLETE_NO_CASE | COMPLETE_DONT_ESCAPE | COMPLETE_NO_SPACE );