aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-01-23 11:12:47 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-01-23 11:12:47 +0200
commit19c37866524f60a7710b256dd13bf1da9f8cff16 (patch)
treef396b93ac6c7f8d9b73d9ebec5cb6a9334bacee3
parent8c5688d77555091615dccd90ea1cf28b89c08d13 (diff)
Change target_key::ext from pointer to pointer to reference to pointer
Probably can also do for the rest of the target_key members.
-rw-r--r--build2/algorithm.ixx2
-rw-r--r--build2/b.cxx2
-rw-r--r--build2/prerequisite4
-rw-r--r--build2/search.cxx26
-rw-r--r--build2/target9
-rw-r--r--build2/target-key10
-rw-r--r--build2/target.cxx12
7 files changed, 35 insertions, 30 deletions
diff --git a/build2/algorithm.ixx b/build2/algorithm.ixx
index 9f6c8bc..cdb76b5 100644
--- a/build2/algorithm.ixx
+++ b/build2/algorithm.ixx
@@ -35,7 +35,7 @@ namespace build2
scope* scope)
{
return search (
- prerequisite_key {nullptr, {&type, &dir, &name, &ext}, scope});
+ prerequisite_key {nullptr, {&type, &dir, &name, ext}, scope});
}
template <typename T>
diff --git a/build2/b.cxx b/build2/b.cxx
index 636951a..cc87cec 100644
--- a/build2/b.cxx
+++ b/build2/b.cxx
@@ -763,7 +763,7 @@ main (int argc, char* argv[])
d.normalize ();
- mif->search (rs, target_key {ti, &d, &tn.value, &e}, l, tgs);
+ mif->search (rs, target_key {ti, &d, &tn.value, e}, l, tgs);
}
}
diff --git a/build2/prerequisite b/build2/prerequisite
index 6ea7fe0..61be2cc 100644
--- a/build2/prerequisite
+++ b/build2/prerequisite
@@ -86,7 +86,7 @@ namespace build2
prerequisite_key
key () const
{
- return prerequisite_key {proj, {&type, &dir, &name, &ext}, &scope};
+ return prerequisite_key {proj, {&type, &dir, &name, ext}, &scope};
}
public:
@@ -125,7 +125,7 @@ namespace build2
std::pair<prerequisite&, bool>
insert (const std::string* proj, const target_key& tk, scope& s, tracer& t)
{
- return insert (proj, *tk.type, *tk.dir, *tk.name, *tk.ext, s, t);
+ return insert (proj, *tk.type, *tk.dir, *tk.name, tk.ext, s, t);
}
};
}
diff --git a/build2/search.cxx b/build2/search.cxx
index 6bb448a..7c27ca5 100644
--- a/build2/search.cxx
+++ b/build2/search.cxx
@@ -42,7 +42,7 @@ namespace build2
}
}
- auto i (targets.find (*tk.type, d, *tk.name, *tk.ext, trace));
+ auto i (targets.find (*tk.type, d, *tk.name, tk.ext, trace));
if (i == targets.end ())
return 0;
@@ -60,20 +60,18 @@ namespace build2
{
tracer trace ("search_existing_file");
- prerequisite_key pk (cpk); // Make a copy so we can update extension.
- target_key& tk (pk.tk);
- assert (tk.dir->relative ());
+ const target_key& ctk (cpk.tk);
+ assert (ctk.dir->relative ());
// Figure out the extension. Pretty similar logic to file::derive_path().
//
- const string* ext (*tk.ext);
+ const string* ext (ctk.ext);
if (ext == nullptr)
{
- if (auto f = tk.type->extension)
+ if (auto f = ctk.type->extension)
{
- ext = &f (tk, *pk.scope); // Already from the pool.
- tk.ext = &ext;
+ ext = &f (ctk, *cpk.scope); // Already from the pool.
}
else
{
@@ -84,13 +82,19 @@ namespace build2
// explicitly, we will still do so). But let me know what you
// think.
//
- //fail << "no default extension for prerequisite " << pk;
+ //fail << "no default extension for prerequisite " << cpk;
level4 ([&]{trace << "no existing file found for prerequisite "
- << pk;});
+ << cpk;});
return nullptr;
}
}
+ // Make a copy with the updated extension.
+ //
+ const prerequisite_key pk {
+ cpk.proj, target_key {ctk.type, ctk.dir, ctk.name, ext}, cpk.scope};
+ const target_key& tk (pk.tk);
+
// Go over paths looking for a file.
//
for (const dir_path& d: sp)
@@ -159,7 +163,7 @@ namespace build2
// Find or insert.
//
- auto r (targets.insert (*tk.type, move (d), *tk.name, *tk.ext, trace));
+ auto r (targets.insert (*tk.type, move (d), *tk.name, tk.ext, trace));
assert (r.second);
target& t (r.first);
diff --git a/build2/target b/build2/target
index 429df71..3d794c8 100644
--- a/build2/target
+++ b/build2/target
@@ -208,7 +208,7 @@ namespace build2
// to the targets's members will be reflected in the key.
//
target_key
- key () const {return target_key {&type (), &dir, &name, &ext};}
+ key () const {return target_key {&type (), &dir, &name, ext};}
// Scoping.
//
@@ -748,6 +748,8 @@ namespace build2
//
struct target_set
{
+ // @@ When we update ext in key, don't we change it? I think we do.
+ //
typedef std::map<target_key, std::unique_ptr<target>> map;
typedef butl::map_iterator_adapter<map::const_iterator> iterator;
@@ -761,7 +763,7 @@ namespace build2
const std::string* ext,
tracer& trace) const
{
- return find (target_key {&type, &dir, &name, &ext}, trace);
+ return find (target_key {&type, &dir, &name, ext}, trace);
}
// As above but ignore the extension and return the target or
@@ -771,8 +773,7 @@ namespace build2
T*
find (const dir_path& dir, const std::string& name) const
{
- const std::string* e (nullptr);
- auto i (map_.find (target_key {&T::static_type, &dir, &name, &e}));
+ auto i (map_.find (target_key {&T::static_type, &dir, &name, nullptr}));
return i != map_.end () ? static_cast<T*> (i->second.get ()) : nullptr;
}
diff --git a/build2/target-key b/build2/target-key
index 2bbc2b2..4246cf2 100644
--- a/build2/target-key
+++ b/build2/target-key
@@ -22,10 +22,10 @@ namespace build2
class target_key
{
public:
- mutable const target_type* type;
- mutable const dir_path* dir;
- mutable const std::string* name;
- mutable const std::string* const* ext; // Note: only *ext can be NULL.
+ const target_type* const type;
+ const dir_path* const dir;
+ const std::string* const name;
+ const std::string* const& ext;
friend bool
operator< (const target_key& x, const target_key& y)
@@ -44,7 +44,7 @@ namespace build2
(xt == yt && *x.name < *y.name) ||
(xt == yt && *x.name == *y.name && *x.dir < *y.dir) ||
(xt == yt && *x.name == *y.name && *x.dir == *y.dir &&
- *x.ext != nullptr && *y.ext != nullptr && **x.ext < **y.ext);
+ x.ext != nullptr && y.ext != nullptr && *x.ext < *y.ext);
}
};
diff --git a/build2/target.cxx b/build2/target.cxx
index 45fee80..0dcf959 100644
--- a/build2/target.cxx
+++ b/build2/target.cxx
@@ -186,7 +186,7 @@ namespace build2
ostream&
operator<< (ostream& os, const target& t)
{
- return os << target_key {&t.type (), &t.dir, &t.name, &t.ext};
+ return os << target_key {&t.type (), &t.dir, &t.name, t.ext};
}
// target_set
@@ -204,7 +204,7 @@ namespace build2
// Update the extension if the existing target has it unspecified.
//
- const string* ext (*k.ext);
+ const string* ext (k.ext);
if (t.ext != ext)
{
level5 ([&]{
@@ -233,14 +233,14 @@ namespace build2
const string* ext,
tracer& trace)
{
- iterator i (find (target_key {&tt, &dir, &name, &ext}, trace));
+ iterator i (find (target_key {&tt, &dir, &name, ext}, trace));
bool r (i == end ());
if (r)
{
unique_ptr<target> pt (tt.factory (tt, move (dir), move (name), ext));
i = map_.emplace (
- make_pair (target_key {&tt, &pt->dir, &pt->name, &pt->ext},
+ make_pair (target_key {&tt, &pt->dir, &pt->name, pt->ext},
move (pt))).first;
}
@@ -265,8 +265,8 @@ namespace build2
{
os << *k.name;
- if (*k.ext != nullptr && !(*k.ext)->empty ())
- os << '.' << **k.ext;
+ if (k.ext != nullptr && !k.ext->empty ())
+ os << '.' << *k.ext;
}
else
os << d;