From 990cbf302eb04f80174c50040492fa7db6fbad6d Mon Sep 17 00:00:00 2001 From: Michael Giacomelli Date: Tue, 14 Dec 2010 21:33:45 +0000 Subject: Commit FS#11799 by Alexander Meshcheryakov. Improves the text viewer plugin to write to the disk less often, and correct several minor bugs. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28833 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/text_viewer/tv_bookmark.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'apps/plugins/text_viewer/tv_bookmark.c') diff --git a/apps/plugins/text_viewer/tv_bookmark.c b/apps/plugins/text_viewer/tv_bookmark.c index 815e7a1f91..5f77d2a92c 100644 --- a/apps/plugins/text_viewer/tv_bookmark.c +++ b/apps/plugins/text_viewer/tv_bookmark.c @@ -32,7 +32,6 @@ enum { TV_BOOKMARK_USER = 2, }; -#define SERIALIZE_BOOKMARK_SIZE 8 struct tv_bookmark_info { struct tv_screen_pos pos; @@ -287,11 +286,8 @@ bool tv_deserialize_bookmarks(int fd) return res; } -static bool tv_write_bookmark_info(int fd, const struct tv_bookmark_info *b) +static void tv_write_bookmark_info(unsigned char *p, const struct tv_bookmark_info *b) { - unsigned char buf[SERIALIZE_BOOKMARK_SIZE]; - unsigned char *p = buf; - *p++ = b->pos.file_pos >> 24; *p++ = b->pos.file_pos >> 16; *p++ = b->pos.file_pos >> 8; @@ -302,21 +298,17 @@ static bool tv_write_bookmark_info(int fd, const struct tv_bookmark_info *b) *p++ = b->pos.line; *p = b->flag; - - return (rb->write(fd, buf, SERIALIZE_BOOKMARK_SIZE) >= 0); } -int tv_serialize_bookmarks(int fd) +int tv_serialize_bookmarks(unsigned char *buf) { int i; - if (rb->write(fd, &bookmark_count, 1) < 0) - return 0; + buf[0] = bookmark_count; for (i = 0; i < bookmark_count; i++) { - if (!tv_write_bookmark_info(fd, &bookmarks[i])) - break; + tv_write_bookmark_info(buf + i * SERIALIZE_BOOKMARK_SIZE + 1, &bookmarks[i]); } return i * SERIALIZE_BOOKMARK_SIZE + 1; } -- cgit v1.2.3