mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-21 12:34:56 +00:00
Make mime_type and mime_charset on the fly
For the same motivation explained in the parent commit, make string_refs on the fly instead of storing them.
This commit is contained in:
parent
8c03ba15bc
commit
6b5fe85571
3 changed files with 39 additions and 10 deletions
|
@ -25,6 +25,7 @@
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <boost/flyweight.hpp>
|
#include <boost/flyweight.hpp>
|
||||||
#include <boost/flyweight/no_locking.hpp>
|
#include <boost/flyweight/no_locking.hpp>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace mchlib {
|
namespace mchlib {
|
||||||
struct FileRecordData {
|
struct FileRecordData {
|
||||||
|
@ -39,11 +40,13 @@ namespace mchlib {
|
||||||
mime_full(),
|
mime_full(),
|
||||||
atime(parATime),
|
atime(parATime),
|
||||||
mtime(parMTime),
|
mtime(parMTime),
|
||||||
mime_type(),
|
|
||||||
mime_charset(),
|
|
||||||
size(0),
|
size(0),
|
||||||
level(parLevel),
|
level(parLevel),
|
||||||
path_offset(0),
|
path_offset(0),
|
||||||
|
mime_type_offset(0),
|
||||||
|
mime_type_length(0),
|
||||||
|
mime_charset_offset(0),
|
||||||
|
mime_charset_length(0),
|
||||||
is_directory(parIsDir),
|
is_directory(parIsDir),
|
||||||
is_symlink(parIsSymLink),
|
is_symlink(parIsSymLink),
|
||||||
unreadable(false),
|
unreadable(false),
|
||||||
|
@ -57,11 +60,13 @@ namespace mchlib {
|
||||||
mime_full(),
|
mime_full(),
|
||||||
atime(parATime),
|
atime(parATime),
|
||||||
mtime(parMTime),
|
mtime(parMTime),
|
||||||
mime_type(),
|
|
||||||
mime_charset(),
|
|
||||||
size(0),
|
size(0),
|
||||||
level(parLevel),
|
level(parLevel),
|
||||||
path_offset(parRelPathOffs),
|
path_offset(parRelPathOffs),
|
||||||
|
mime_type_offset(0),
|
||||||
|
mime_type_length(0),
|
||||||
|
mime_charset_offset(0),
|
||||||
|
mime_charset_length(0),
|
||||||
is_directory(parIsDir),
|
is_directory(parIsDir),
|
||||||
is_symlink(parIsSymLink),
|
is_symlink(parIsSymLink),
|
||||||
unreadable(false),
|
unreadable(false),
|
||||||
|
@ -83,17 +88,42 @@ namespace mchlib {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
boost::string_ref path ( void ) const { return boost::string_ref(abs_path).substr(path_offset); }
|
boost::string_ref path ( void ) const { return boost::string_ref(abs_path).substr(path_offset); }
|
||||||
|
boost::string_ref mime_type ( void ) const { return boost::string_ref(mime_full.get()).substr(mime_type_offset, mime_type_length); }
|
||||||
|
boost::string_ref mime_charset ( void ) const { return boost::string_ref(mime_full.get()).substr(mime_charset_offset, mime_charset_length); }
|
||||||
|
void set_mime_parts ( boost::string_ref parType, boost::string_ref parCharset ) {
|
||||||
|
const auto& mime = mime_full.get();
|
||||||
|
{
|
||||||
|
assert(std::less<const char*>()(mime.data(), parType.data()));
|
||||||
|
assert(std::less_equal<const char*>()(parType.data() + parType.size(), mime.data()));
|
||||||
|
assert(parType.data() - mime.data() < USHRT_MAX);
|
||||||
|
assert(parType.size() < USHRT_MAX);
|
||||||
|
assert(parType.size() + (parType.data() - mime.data()) <= mime.size());
|
||||||
|
mime_type_offset = static_cast<uint16_t>(parType.data() - mime.data());
|
||||||
|
mime_type_length = static_cast<uint16_t>(parType.size());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
assert(std::less<const char*>()(mime.data(), parCharset.data()));
|
||||||
|
assert(std::less_equal<const char*>()(parCharset.data() + parCharset.size(), mime.data()));
|
||||||
|
assert(parCharset.data() - mime.data() < USHRT_MAX);
|
||||||
|
assert(parCharset.size() < USHRT_MAX);
|
||||||
|
assert(parCharset.size() + (parCharset.data() - mime.data()) <= mime.size());
|
||||||
|
mime_charset_offset = static_cast<uint16_t>(parCharset.data() - mime.data());
|
||||||
|
mime_charset_length = static_cast<uint16_t>(parCharset.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TigerHash hash;
|
TigerHash hash;
|
||||||
std::string abs_path;
|
std::string abs_path;
|
||||||
mime_string mime_full;
|
mime_string mime_full;
|
||||||
std::time_t atime;
|
std::time_t atime;
|
||||||
std::time_t mtime;
|
std::time_t mtime;
|
||||||
boost::string_ref mime_type;
|
|
||||||
boost::string_ref mime_charset;
|
|
||||||
uint64_t size;
|
uint64_t size;
|
||||||
uint16_t level;
|
uint16_t level;
|
||||||
uint16_t path_offset; //Relative path starting character into abs_path
|
uint16_t path_offset; //Relative path starting character into abs_path
|
||||||
|
uint16_t mime_type_offset; //Mime type starting character into mime_full
|
||||||
|
uint16_t mime_type_length; //Mime type string length
|
||||||
|
uint16_t mime_charset_offset; //Mime charset starting character into mime_full
|
||||||
|
uint16_t mime_charset_length; //Mime charset string length
|
||||||
bool is_directory;
|
bool is_directory;
|
||||||
bool is_symlink;
|
bool is_symlink;
|
||||||
bool unreadable;
|
bool unreadable;
|
||||||
|
|
|
@ -41,8 +41,7 @@ namespace mchlib {
|
||||||
for (auto& itm : list) {
|
for (auto& itm : list) {
|
||||||
itm.mime_full = mime.analyze(itm.abs_path);
|
itm.mime_full = mime.analyze(itm.abs_path);
|
||||||
auto mime_pair = split_mime(itm.mime_full);
|
auto mime_pair = split_mime(itm.mime_full);
|
||||||
itm.mime_type = mime_pair.first;
|
itm.set_mime_parts(mime_pair.first, mime_pair.second);
|
||||||
itm.mime_charset = mime_pair.second;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,8 +138,8 @@ namespace din {
|
||||||
system_clock::from_time_t(itm.mtime),
|
system_clock::from_time_t(itm.mtime),
|
||||||
itm.hash_valid,
|
itm.hash_valid,
|
||||||
itm.unreadable,
|
itm.unreadable,
|
||||||
itm.mime_type,
|
itm.mime_type(),
|
||||||
itm.mime_charset
|
itm.mime_charset()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
conn.query("COMMIT;");
|
conn.query("COMMIT;");
|
||||||
|
|
Loading…
Add table
Reference in a new issue