trafficserver-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From SolidWallOfCode <>
Subject [GitHub] trafficserver pull request: Maintain and use a mapping of hostname...
Date Thu, 02 Jul 2015 18:54:31 GMT
Github user SolidWallOfCode commented on a diff in the pull request:
    --- Diff: iocore/hostdb/P_HostDBProcessor.h ---
    @@ -190,6 +190,14 @@ extern RecRawStatBlock *hostdb_rsb;
     #define HOSTDB_DECREMENT_THREAD_DYN_STAT(_s, _t) RecIncrRawStatSum(hostdb_rsb, _t, (int)_s,
    +struct CmpStrCaseInsensitive {
    +  bool operator()(const std::string &a, const std::string &b) const { return
strcasecmp(a.c_str(), b.c_str()) == 0; }
    +// A to hold a ref-counted map
    +struct RefCountedHostsFileMap : public RefCountObj {
    +  std::map<std::string, IpAddr, CmpStrCaseInsensitive> hosts_file_map;
    --- End diff --
    I'd do this differently. You have to read in the file. If you look at the original code
that file buffer is kept for the lifetime of the use of the hosts names and the actual "strings"
that are the host names are just pointers in to that buffer. This is a bit memory inefficient
because you keep the address strings in memory but involves many fewer allocations because
you don't have to copy or allocate for the strings and the memory management is easy since
it's all one unit.
    In that case you 'd use `ts::ConstBuffer` as your string type and use an appropriate comparison
    This also makes searching faster as you can use ts::ConstBuffer from the input name trivially
and the lifetime of that is sufficient for the search. Look at PR 229, in `` around
line 122, for an example that does exactly this.

If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at or file a JIRA ticket
with INFRA.

View raw message