From ab7a6c09998b09d7648110a662655c2c1ee5f6d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 26 Jul 2009 23:44:48 +0000 Subject: [PATCH] Implemented experimental precaching of the system font files during starting the app_server. Should in theory reduce disk seeks when booting from CD. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31788 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/FontManager.cpp | 43 ++++++++++++++++++++++++++++++--- src/servers/app/FontManager.h | 1 + 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/servers/app/FontManager.cpp b/src/servers/app/FontManager.cpp index 4a81e2cef5..f422e9c891 100644 --- a/src/servers/app/FontManager.cpp +++ b/src/servers/app/FontManager.cpp @@ -27,8 +27,6 @@ #include -using std::nothrow; - //#define TRACE_FONT_MANAGER #ifdef TRACE_FONT_MANAGER # define FTRACE(x) printf x @@ -115,6 +113,12 @@ FontManager::FontManager() _LoadRecentFontMappings(); fInitStatus = _SetDefaultFonts(); + + if (fInitStatus == B_OK) { + // Precache the plain and bold fonts + _PrecacheFontFile(fDefaultPlainFont); + _PrecacheFontFile(fDefaultBoldFont); + } } } @@ -332,6 +336,8 @@ FontManager::_LoadRecentFontMappings() veraFontPath.SetTo(ttfontsPath.Path()); veraFontPath.Append("DejaVuSansMono.ttf"); _AddDefaultMapping("DejaVu Sans Mono", "Book", veraFontPath.Path()); + + return true; } return false; @@ -482,6 +488,37 @@ FontManager::_SetDefaultFonts() } +void +FontManager::_PrecacheFontFile(const ServerFont* font) +{ + if (font == NULL) + return; + + size_t bufferSize = 32768; + uint8* buffer = new (std::nothrow) uint8[bufferSize]; + if (buffer == NULL) { + // We don't care. Pre-caching doesn't make sense anyways when there + // is not enough RAM... + return; + } + + BFile file(font->Path(), B_READ_ONLY); + if (file.InitCheck() != B_OK) { + delete[] buffer; + return; + } + + while (true) { + // We just want the file in the kernel file cache... + ssize_t read = file.Read(buffer, bufferSize); + if (read < bufferSize) + break; + } + + delete[] buffer; +} + + void FontManager::_AddSystemPaths() { @@ -570,7 +607,7 @@ FontManager::_AddFont(font_directory& directory, BEntry& entry) if (!family->AddStyle(style)) { delete style; delete family; - return B_NO_MEMORY; + return B_NO_MEMORY; } directory.styles.AddItem(style); diff --git a/src/servers/app/FontManager.h b/src/servers/app/FontManager.h index 2f4d7c5ba5..74fdc38ff7 100644 --- a/src/servers/app/FontManager.h +++ b/src/servers/app/FontManager.h @@ -88,6 +88,7 @@ private: const char* fallbackStyle, uint16 fallbackFace); status_t _SetDefaultFonts(); + void _PrecacheFontFile(const ServerFont* font); void _AddSystemPaths(); font_directory* _FindDirectory(node_ref& nodeRef); void _RemoveDirectory(font_directory* directory);