Commit afab92d8 by Thomas Koenig

file_pos.c (unformatted_backspace): Normal case is GFC_CONVERT_NATIVE.

2008-10-16  Thomas Koenig  <tkoenig@gcc.gnu.org>

	* io/file_pos.c (unformatted_backspace): Normal case is
	GFC_CONVERT_NATIVE.
	* io/transfer.c (read_sf):  Mark paths leading to generate_error()
	as unlikely.
	(readl_block_form):  Likewise.
	(read_block_direct):  Likewise.
	(write_block):  Likewise.
	(write_buf):  Likewise.
	(us_read):  Likewise.  Normal case is GFC_CONVERT_NATIVE.
	(next_record_w_unf):  Mark paths leading to generate_error()
	as unlikely.

From-SVN: r141179
parent 74e8018e
2008-10-16 Thomas Koenig <tkoenig@gcc.gnu.org> 2008-10-16 Thomas Koenig <tkoenig@gcc.gnu.org>
* io/file_pos.c (unformatted_backspace): Normal case is
GFC_CONVERT_NATIVE.
* io/transfer.c (read_sf): Mark paths leading to generate_error()
as unlikely.
(readl_block_form): Likewise.
(read_block_direct): Likewise.
(write_block): Likewise.
(write_buf): Likewise.
(us_read): Likewise. Normal case is GFC_CONVERT_NATIVE.
(next_record_w_unf): Mark paths leading to generate_error()
as unlikely.
2008-10-16 Thomas Koenig <tkoenig@gcc.gnu.org>
PR libfortran/34670 PR libfortran/34670
* generated/spread_r4.c: Regenerated. * generated/spread_r4.c: Regenerated.
......
...@@ -120,7 +120,7 @@ unformatted_backspace (st_parameter_filepos *fpp, gfc_unit *u) ...@@ -120,7 +120,7 @@ unformatted_backspace (st_parameter_filepos *fpp, gfc_unit *u)
goto io_error; goto io_error;
/* Only GFC_CONVERT_NATIVE and GFC_CONVERT_SWAP are valid here. */ /* Only GFC_CONVERT_NATIVE and GFC_CONVERT_SWAP are valid here. */
if (u->flags.convert == GFC_CONVERT_NATIVE) if (likely (u->flags.convert == GFC_CONVERT_NATIVE))
{ {
switch (length) switch (length)
{ {
......
...@@ -205,7 +205,8 @@ read_sf (st_parameter_dt *dtp, int *length, int no_error) ...@@ -205,7 +205,8 @@ read_sf (st_parameter_dt *dtp, int *length, int no_error)
if (is_internal_unit (dtp)) if (is_internal_unit (dtp))
{ {
readlen = *length; readlen = *length;
if (sread (dtp->u.p.current_unit->s, p, &readlen) != 0 || readlen < (size_t) *length) if (unlikely (sread (dtp->u.p.current_unit->s, p, &readlen) != 0
|| readlen < (size_t) *length))
{ {
generate_error (&dtp->common, LIBERROR_END, NULL); generate_error (&dtp->common, LIBERROR_END, NULL);
return NULL; return NULL;
...@@ -219,7 +220,7 @@ read_sf (st_parameter_dt *dtp, int *length, int no_error) ...@@ -219,7 +220,7 @@ read_sf (st_parameter_dt *dtp, int *length, int no_error)
do do
{ {
if (sread (dtp->u.p.current_unit->s, &q, &readlen) != 0) if (unlikely (sread (dtp->u.p.current_unit->s, &q, &readlen) != 0))
{ {
generate_error (&dtp->common, LIBERROR_END, NULL); generate_error (&dtp->common, LIBERROR_END, NULL);
return NULL; return NULL;
...@@ -229,7 +230,7 @@ read_sf (st_parameter_dt *dtp, int *length, int no_error) ...@@ -229,7 +230,7 @@ read_sf (st_parameter_dt *dtp, int *length, int no_error)
EOR below. */ EOR below. */
if (readlen < 1 && n == 0) if (readlen < 1 && n == 0)
{ {
if (no_error) if (likely (no_error))
break; break;
generate_error (&dtp->common, LIBERROR_END, NULL); generate_error (&dtp->common, LIBERROR_END, NULL);
return NULL; return NULL;
...@@ -250,7 +251,8 @@ read_sf (st_parameter_dt *dtp, int *length, int no_error) ...@@ -250,7 +251,8 @@ read_sf (st_parameter_dt *dtp, int *length, int no_error)
{ {
readlen = 1; readlen = 1;
pos = stream_offset (dtp->u.p.current_unit->s); pos = stream_offset (dtp->u.p.current_unit->s);
if (sread (dtp->u.p.current_unit->s, &q, &readlen) != 0) if (unlikely (sread (dtp->u.p.current_unit->s, &q, &readlen)
!= 0))
{ {
generate_error (&dtp->common, LIBERROR_END, NULL); generate_error (&dtp->common, LIBERROR_END, NULL);
return NULL; return NULL;
...@@ -266,7 +268,7 @@ read_sf (st_parameter_dt *dtp, int *length, int no_error) ...@@ -266,7 +268,7 @@ read_sf (st_parameter_dt *dtp, int *length, int no_error)
so we can just continue with a short read. */ so we can just continue with a short read. */
if (dtp->u.p.current_unit->pad_status == PAD_NO) if (dtp->u.p.current_unit->pad_status == PAD_NO)
{ {
if (no_error) if (likely (no_error))
break; break;
generate_error (&dtp->common, LIBERROR_EOR, NULL); generate_error (&dtp->common, LIBERROR_EOR, NULL);
return NULL; return NULL;
...@@ -332,7 +334,7 @@ read_block_form (st_parameter_dt *dtp, void *buf, size_t *nbytes) ...@@ -332,7 +334,7 @@ read_block_form (st_parameter_dt *dtp, void *buf, size_t *nbytes)
dtp->u.p.current_unit->bytes_left = dtp->u.p.current_unit->recl; dtp->u.p.current_unit->bytes_left = dtp->u.p.current_unit->recl;
else else
{ {
if (dtp->u.p.current_unit->pad_status == PAD_NO) if (unlikely (dtp->u.p.current_unit->pad_status == PAD_NO))
{ {
/* Not enough data left. */ /* Not enough data left. */
generate_error (&dtp->common, LIBERROR_EOR, NULL); generate_error (&dtp->common, LIBERROR_EOR, NULL);
...@@ -340,7 +342,7 @@ read_block_form (st_parameter_dt *dtp, void *buf, size_t *nbytes) ...@@ -340,7 +342,7 @@ read_block_form (st_parameter_dt *dtp, void *buf, size_t *nbytes)
} }
} }
if (dtp->u.p.current_unit->bytes_left == 0) if (unlikely (dtp->u.p.current_unit->bytes_left == 0))
{ {
dtp->u.p.current_unit->endfile = AT_ENDFILE; dtp->u.p.current_unit->endfile = AT_ENDFILE;
generate_error (&dtp->common, LIBERROR_END, NULL); generate_error (&dtp->common, LIBERROR_END, NULL);
...@@ -368,7 +370,7 @@ read_block_form (st_parameter_dt *dtp, void *buf, size_t *nbytes) ...@@ -368,7 +370,7 @@ read_block_form (st_parameter_dt *dtp, void *buf, size_t *nbytes)
dtp->u.p.current_unit->bytes_left -= (gfc_offset) *nbytes; dtp->u.p.current_unit->bytes_left -= (gfc_offset) *nbytes;
nread = *nbytes; nread = *nbytes;
if (sread (dtp->u.p.current_unit->s, buf, &nread) != 0) if (unlikely (sread (dtp->u.p.current_unit->s, buf, &nread) != 0))
{ {
generate_error (&dtp->common, LIBERROR_OS, NULL); generate_error (&dtp->common, LIBERROR_OS, NULL);
return FAILURE; return FAILURE;
...@@ -379,7 +381,7 @@ read_block_form (st_parameter_dt *dtp, void *buf, size_t *nbytes) ...@@ -379,7 +381,7 @@ read_block_form (st_parameter_dt *dtp, void *buf, size_t *nbytes)
if (nread != *nbytes) if (nread != *nbytes)
{ /* Short read, this shouldn't happen. */ { /* Short read, this shouldn't happen. */
if (dtp->u.p.current_unit->pad_status == PAD_YES) if (likely (dtp->u.p.current_unit->pad_status == PAD_YES))
*nbytes = nread; *nbytes = nread;
else else
{ {
...@@ -410,7 +412,8 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes) ...@@ -410,7 +412,8 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes)
{ {
to_read_record = *nbytes; to_read_record = *nbytes;
have_read_record = to_read_record; have_read_record = to_read_record;
if (sread (dtp->u.p.current_unit->s, buf, &have_read_record) != 0) if (unlikely (sread (dtp->u.p.current_unit->s, buf, &have_read_record)
!= 0))
{ {
generate_error (&dtp->common, LIBERROR_OS, NULL); generate_error (&dtp->common, LIBERROR_OS, NULL);
return; return;
...@@ -418,7 +421,7 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes) ...@@ -418,7 +421,7 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes)
dtp->u.p.current_unit->strm_pos += (gfc_offset) have_read_record; dtp->u.p.current_unit->strm_pos += (gfc_offset) have_read_record;
if (to_read_record != have_read_record) if (unlikely (to_read_record != have_read_record))
{ {
/* Short read, e.g. if we hit EOF. For stream files, /* Short read, e.g. if we hit EOF. For stream files,
we have to set the end-of-file condition. */ we have to set the end-of-file condition. */
...@@ -445,7 +448,8 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes) ...@@ -445,7 +448,8 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes)
dtp->u.p.current_unit->bytes_left -= to_read_record; dtp->u.p.current_unit->bytes_left -= to_read_record;
if (sread (dtp->u.p.current_unit->s, buf, &to_read_record) != 0) if (unlikely (sread (dtp->u.p.current_unit->s, buf, &to_read_record)
!= 0))
{ {
generate_error (&dtp->common, LIBERROR_OS, NULL); generate_error (&dtp->common, LIBERROR_OS, NULL);
return; return;
...@@ -459,7 +463,7 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes) ...@@ -459,7 +463,7 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes)
return; return;
} }
if (short_record) if (unlikely (short_record))
{ {
generate_error (&dtp->common, LIBERROR_SHORT_RECORD, NULL); generate_error (&dtp->common, LIBERROR_SHORT_RECORD, NULL);
return; return;
...@@ -471,7 +475,7 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes) ...@@ -471,7 +475,7 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes)
until the request has been fulfilled or the record has run out until the request has been fulfilled or the record has run out
of continuation subrecords. */ of continuation subrecords. */
if (dtp->u.p.current_unit->endfile == AT_ENDFILE) if (unlikely (dtp->u.p.current_unit->endfile == AT_ENDFILE))
{ {
generate_error (&dtp->common, LIBERROR_END, NULL); generate_error (&dtp->common, LIBERROR_END, NULL);
return; return;
...@@ -509,8 +513,8 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes) ...@@ -509,8 +513,8 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes)
dtp->u.p.current_unit->bytes_left_subrecord -= to_read_subrecord; dtp->u.p.current_unit->bytes_left_subrecord -= to_read_subrecord;
have_read_subrecord = to_read_subrecord; have_read_subrecord = to_read_subrecord;
if (sread (dtp->u.p.current_unit->s, buf + have_read_record, if (unlikely (sread (dtp->u.p.current_unit->s, buf + have_read_record,
&have_read_subrecord) != 0) &have_read_subrecord) != 0))
{ {
generate_error (&dtp->common, LIBERROR_OS, NULL); generate_error (&dtp->common, LIBERROR_OS, NULL);
return; return;
...@@ -518,7 +522,7 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes) ...@@ -518,7 +522,7 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes)
have_read_record += have_read_subrecord; have_read_record += have_read_subrecord;
if (to_read_subrecord != have_read_subrecord) if (unlikely (to_read_subrecord != have_read_subrecord))
{ {
/* Short read, e.g. if we hit EOF. This means the record /* Short read, e.g. if we hit EOF. This means the record
...@@ -532,7 +536,7 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes) ...@@ -532,7 +536,7 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes)
if (to_read_record > 0) if (to_read_record > 0)
{ {
if (dtp->u.p.current_unit->continued) if (likely (dtp->u.p.current_unit->continued))
{ {
next_record_r_unf (dtp, 0); next_record_r_unf (dtp, 0);
us_read (dtp, 1); us_read (dtp, 1);
...@@ -556,7 +560,7 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes) ...@@ -556,7 +560,7 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes)
} }
dtp->u.p.current_unit->bytes_left -= have_read_record; dtp->u.p.current_unit->bytes_left -= have_read_record;
if (short_record) if (unlikely (short_record))
{ {
generate_error (&dtp->common, LIBERROR_SHORT_RECORD, NULL); generate_error (&dtp->common, LIBERROR_SHORT_RECORD, NULL);
return; return;
...@@ -581,9 +585,11 @@ write_block (st_parameter_dt *dtp, int length) ...@@ -581,9 +585,11 @@ write_block (st_parameter_dt *dtp, int length)
{ {
/* For preconnected units with default record length, set bytes left /* For preconnected units with default record length, set bytes left
to unit record length and proceed, otherwise error. */ to unit record length and proceed, otherwise error. */
if ((dtp->u.p.current_unit->unit_number == options.stdout_unit if (likely ((dtp->u.p.current_unit->unit_number
|| dtp->u.p.current_unit->unit_number == options.stderr_unit) == options.stdout_unit
&& dtp->u.p.current_unit->recl == DEFAULT_RECL) || dtp->u.p.current_unit->unit_number
== options.stderr_unit)
&& dtp->u.p.current_unit->recl == DEFAULT_RECL))
dtp->u.p.current_unit->bytes_left = dtp->u.p.current_unit->recl; dtp->u.p.current_unit->bytes_left = dtp->u.p.current_unit->recl;
else else
{ {
...@@ -605,7 +611,7 @@ write_block (st_parameter_dt *dtp, int length) ...@@ -605,7 +611,7 @@ write_block (st_parameter_dt *dtp, int length)
return NULL; return NULL;
} }
if (dtp->u.p.current_unit->endfile == AT_ENDFILE) if (unlikely (dtp->u.p.current_unit->endfile == AT_ENDFILE))
generate_error (&dtp->common, LIBERROR_END, NULL); generate_error (&dtp->common, LIBERROR_END, NULL);
} }
else else
...@@ -642,7 +648,7 @@ write_buf (st_parameter_dt *dtp, void *buf, size_t nbytes) ...@@ -642,7 +648,7 @@ write_buf (st_parameter_dt *dtp, void *buf, size_t nbytes)
if (is_stream_io (dtp)) if (is_stream_io (dtp))
{ {
if (swrite (dtp->u.p.current_unit->s, buf, &nbytes) != 0) if (unlikely (swrite (dtp->u.p.current_unit->s, buf, &nbytes) != 0))
{ {
generate_error (&dtp->common, LIBERROR_OS, NULL); generate_error (&dtp->common, LIBERROR_OS, NULL);
return FAILURE; return FAILURE;
...@@ -657,7 +663,7 @@ write_buf (st_parameter_dt *dtp, void *buf, size_t nbytes) ...@@ -657,7 +663,7 @@ write_buf (st_parameter_dt *dtp, void *buf, size_t nbytes)
if (dtp->u.p.current_unit->flags.access == ACCESS_DIRECT) if (dtp->u.p.current_unit->flags.access == ACCESS_DIRECT)
{ {
if (dtp->u.p.current_unit->bytes_left < (gfc_offset) nbytes) if (unlikely (dtp->u.p.current_unit->bytes_left < (gfc_offset) nbytes))
{ {
generate_error (&dtp->common, LIBERROR_DIRECT_EOR, NULL); generate_error (&dtp->common, LIBERROR_DIRECT_EOR, NULL);
return FAILURE; return FAILURE;
...@@ -666,7 +672,7 @@ write_buf (st_parameter_dt *dtp, void *buf, size_t nbytes) ...@@ -666,7 +672,7 @@ write_buf (st_parameter_dt *dtp, void *buf, size_t nbytes)
if (buf == NULL && nbytes == 0) if (buf == NULL && nbytes == 0)
return SUCCESS; return SUCCESS;
if (swrite (dtp->u.p.current_unit->s, buf, &nbytes) != 0) if (unlikely (swrite (dtp->u.p.current_unit->s, buf, &nbytes) != 0))
{ {
generate_error (&dtp->common, LIBERROR_OS, NULL); generate_error (&dtp->common, LIBERROR_OS, NULL);
return FAILURE; return FAILURE;
...@@ -703,8 +709,8 @@ write_buf (st_parameter_dt *dtp, void *buf, size_t nbytes) ...@@ -703,8 +709,8 @@ write_buf (st_parameter_dt *dtp, void *buf, size_t nbytes)
dtp->u.p.current_unit->bytes_left_subrecord -= dtp->u.p.current_unit->bytes_left_subrecord -=
(gfc_offset) to_write_subrecord; (gfc_offset) to_write_subrecord;
if (swrite (dtp->u.p.current_unit->s, buf + have_written, if (unlikely (swrite (dtp->u.p.current_unit->s, buf + have_written,
&to_write_subrecord) != 0) &to_write_subrecord) != 0))
{ {
generate_error (&dtp->common, LIBERROR_OS, NULL); generate_error (&dtp->common, LIBERROR_OS, NULL);
return FAILURE; return FAILURE;
...@@ -721,7 +727,7 @@ write_buf (st_parameter_dt *dtp, void *buf, size_t nbytes) ...@@ -721,7 +727,7 @@ write_buf (st_parameter_dt *dtp, void *buf, size_t nbytes)
us_write (dtp, 1); us_write (dtp, 1);
} }
dtp->u.p.current_unit->bytes_left -= have_written; dtp->u.p.current_unit->bytes_left -= have_written;
if (short_record) if (unlikely (short_record))
{ {
generate_error (&dtp->common, LIBERROR_SHORT_RECORD, NULL); generate_error (&dtp->common, LIBERROR_SHORT_RECORD, NULL);
return FAILURE; return FAILURE;
...@@ -973,7 +979,7 @@ formatted_transfer_scalar (st_parameter_dt *dtp, bt type, void *p, int kind, ...@@ -973,7 +979,7 @@ formatted_transfer_scalar (st_parameter_dt *dtp, bt type, void *p, int kind,
if (f == NULL) if (f == NULL)
{ {
/* No data descriptors left. */ /* No data descriptors left. */
if (n > 0) if (unlikely (n > 0))
generate_error (&dtp->common, LIBERROR_FORMAT, generate_error (&dtp->common, LIBERROR_FORMAT,
"Insufficient data descriptors in format after reversion"); "Insufficient data descriptors in format after reversion");
return; return;
...@@ -1671,7 +1677,7 @@ us_read (st_parameter_dt *dtp, int continued) ...@@ -1671,7 +1677,7 @@ us_read (st_parameter_dt *dtp, int continued)
nr = n; nr = n;
if (sread (dtp->u.p.current_unit->s, &i, &n) != 0) if (unlikely (sread (dtp->u.p.current_unit->s, &i, &n) != 0))
{ {
generate_error (&dtp->common, LIBERROR_BAD_US, NULL); generate_error (&dtp->common, LIBERROR_BAD_US, NULL);
return; return;
...@@ -1683,14 +1689,14 @@ us_read (st_parameter_dt *dtp, int continued) ...@@ -1683,14 +1689,14 @@ us_read (st_parameter_dt *dtp, int continued)
return; /* end of file */ return; /* end of file */
} }
if (n != nr) if (unlikely (n != nr))
{ {
generate_error (&dtp->common, LIBERROR_BAD_US, NULL); generate_error (&dtp->common, LIBERROR_BAD_US, NULL);
return; return;
} }
/* Only GFC_CONVERT_NATIVE and GFC_CONVERT_SWAP are valid here. */ /* Only GFC_CONVERT_NATIVE and GFC_CONVERT_SWAP are valid here. */
if (dtp->u.p.current_unit->flags.convert == GFC_CONVERT_NATIVE) if (likely (dtp->u.p.current_unit->flags.convert == GFC_CONVERT_NATIVE))
{ {
switch (nr) switch (nr)
{ {
...@@ -2535,7 +2541,7 @@ write_us_marker (st_parameter_dt *dtp, const gfc_offset buf) ...@@ -2535,7 +2541,7 @@ write_us_marker (st_parameter_dt *dtp, const gfc_offset buf)
len = compile_options.record_marker; len = compile_options.record_marker;
/* Only GFC_CONVERT_NATIVE and GFC_CONVERT_SWAP are valid here. */ /* Only GFC_CONVERT_NATIVE and GFC_CONVERT_SWAP are valid here. */
if (dtp->u.p.current_unit->flags.convert == GFC_CONVERT_NATIVE) if (likely (dtp->u.p.current_unit->flags.convert == GFC_CONVERT_NATIVE))
{ {
switch (len) switch (len)
{ {
...@@ -2600,7 +2606,7 @@ next_record_w_unf (st_parameter_dt *dtp, int next_subrecord) ...@@ -2600,7 +2606,7 @@ next_record_w_unf (st_parameter_dt *dtp, int next_subrecord)
else else
m_write = m; m_write = m;
if (write_us_marker (dtp, m_write) != 0) if (unlikely (write_us_marker (dtp, m_write) != 0))
goto io_error; goto io_error;
if (compile_options.record_marker == 0) if (compile_options.record_marker == 0)
...@@ -2611,8 +2617,8 @@ next_record_w_unf (st_parameter_dt *dtp, int next_subrecord) ...@@ -2611,8 +2617,8 @@ next_record_w_unf (st_parameter_dt *dtp, int next_subrecord)
/* Seek to the head and overwrite the bogus length with the real /* Seek to the head and overwrite the bogus length with the real
length. */ length. */
if (sseek (dtp->u.p.current_unit->s, c - m - record_marker) if (unlikely (sseek (dtp->u.p.current_unit->s, c - m - record_marker)
== FAILURE) == FAILURE))
goto io_error; goto io_error;
if (next_subrecord) if (next_subrecord)
...@@ -2620,12 +2626,13 @@ next_record_w_unf (st_parameter_dt *dtp, int next_subrecord) ...@@ -2620,12 +2626,13 @@ next_record_w_unf (st_parameter_dt *dtp, int next_subrecord)
else else
m_write = m; m_write = m;
if (write_us_marker (dtp, m_write) != 0) if (unlikely (write_us_marker (dtp, m_write) != 0))
goto io_error; goto io_error;
/* Seek past the end of the current record. */ /* Seek past the end of the current record. */
if (sseek (dtp->u.p.current_unit->s, c + record_marker) == FAILURE) if (unlikely (sseek (dtp->u.p.current_unit->s, c + record_marker)
== FAILURE))
goto io_error; goto io_error;
return; return;
......
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