Commit 560a74da authored by Per Cederqvist's avatar Per Cederqvist

patch refactor-cached_get_text.patch

parent de22d96e
add-text_store
introduce-generation_position
From: Per Cederqvist <ceder@lysator.liu.se>
Subject: patch introduce-generation_position.patch
Subject: patch refactor-cached_get_text.patch
......@@ -56,6 +56,8 @@
#ifdef TIME_SYNC
# include <sys/resource.h>
#endif
#include <string.h>
#include <errno.h>
#include "ldifftime.h"
#include "exp.h"
......@@ -323,23 +325,29 @@ extern String
cached_get_text( Text_no text )
{
String the_string;
Text_stat *t_stat;
TEXT_RANGE("cached_get_text\n", text, EMPTY_STRING);
TRACE2("cached_get_text %lu\n", text);
if ( text_arr[ text ] == NULL )
if ( (t_stat = cached_get_text_stat (text)) == NULL )
return EMPTY_STRING;
else if (text_arr[text]->text_store.generation == 0)
else if (t_stat->text_store.generation == 0)
{
the_string.string = tmp_alloc( text_arr[text]->no_of_chars );
the_string.len = text_arr[text]->no_of_chars;
fseek(text_file, text_arr[ text ]->text_store.file_pos, SEEK_SET);
the_string.string = tmp_alloc( t_stat->no_of_chars );
the_string.len = t_stat->no_of_chars;
if (fseek(text_file, t_stat->text_store.file_pos, SEEK_SET) != 0)
{
kom_log("Failed to seek to %ld in text mass file: %s.\n",
t_stat->text_store.file_pos, strerror(errno));
return EMPTY_STRING;
}
if ( fread(the_string.string, sizeof(char), the_string.len, text_file)
!= (size_t)the_string.len )
{
kom_log("%s read enough characters of text %lu\n",
"WARNING: cached_get_text: couldn't",
(unsigned long)text);
kom_log("WARNING: cached_get_text: premature end on text %lu\n",
text);
return EMPTY_STRING;
}
return the_string;
......@@ -347,7 +355,7 @@ cached_get_text( Text_no text )
else
{
#warning Generation > 0 not yet handled
return EMPTY_STRING;
restart_kom("Only generation 0 is handled.\n");
}
}
......
......@@ -1048,13 +1048,13 @@ cached_get_text( Text_no text )
String the_string;
Text_stat *t_stat;
LOGACC(lt_text_mass, text);
TRACE2("cached_get_text %lu\n", text);
if ( (t_stat = cached_get_text_stat (text)) == NULL )
return EMPTY_STRING;
else if (t_stat->text_store.generation == 0)
{
LOGACC(lt_text_mass, text);
the_string.string = tmp_alloc( t_stat->no_of_chars );
the_string.len = t_stat->no_of_chars;
if (fseek(text_file, t_stat->text_store.file_pos, SEEK_SET) != 0)
......@@ -1068,7 +1068,7 @@ cached_get_text( Text_no text )
!= (size_t)the_string.len )
{
kom_log("WARNING: cached_get_text: premature end on text %lu\n",
text);
text);
return EMPTY_STRING;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment