ltlparse, eltlparse: avoid unnecessary calls to strlen().
* src/ltlparse/ltlscan.ll, src/ltlparse/parsedecl.hh (flex_set_buffer): Take a std::string as argument and call yy_scan_bytes() with the string size() instead of calling yy_scan_string() which does strlen() on the supplied string. * src/ltlparse/ltlparse.yy: Adjust calls. * src/eltlparse/eltlscan.ll, src/eltlparse/parsedecl.hh, src/eltlparse/eltlparse.yy: Use a similar interface. This also fixes a memory leak as the scanned buffer was not released.
This commit is contained in:
parent
0c06844655
commit
e2143c0313
6 changed files with 36 additions and 21 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/* -*- coding: utf-8 -*-
|
||||
** Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013 Laboratoire de
|
||||
** Recherche et Développement de l'Epita (LRDE).
|
||||
** Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Laboratoire
|
||||
** de Recherche et Développement de l'Epita (LRDE).
|
||||
**
|
||||
** This file is part of Spot, a model checking library.
|
||||
**
|
||||
|
|
@ -552,7 +552,7 @@ namespace spot
|
|||
environment& env,
|
||||
bool debug)
|
||||
{
|
||||
flex_scan_string(eltl_string.c_str());
|
||||
flex_set_buffer(eltl_string);
|
||||
const formula* result = 0;
|
||||
nfamap nmap;
|
||||
aliasmap amap;
|
||||
|
|
@ -561,6 +561,7 @@ namespace spot
|
|||
parser.set_debug_level(debug);
|
||||
parser.parse();
|
||||
error_list = pe.list_;
|
||||
flex_unset_buffer();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
/* Copyright (C) 2008 Laboratoire de Recherche et Développement
|
||||
/* -*- coding: utf-8 -*-
|
||||
** Copyright (C) 2008, 2014 Laboratoire de Recherche et Développement
|
||||
** de l'Epita (LRDE).
|
||||
**
|
||||
** This file is part of Spot, a model checking library.
|
||||
|
|
@ -19,6 +20,7 @@
|
|||
%option noyywrap
|
||||
%option prefix="eltlyy"
|
||||
%option outfile="lex.yy.c"
|
||||
%option stack
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
|
|
@ -190,9 +192,19 @@ namespace spot
|
|||
}
|
||||
|
||||
void
|
||||
flex_scan_string(const char* s)
|
||||
flex_set_buffer(const std::string& buf)
|
||||
{
|
||||
yy_scan_string(s);
|
||||
yypush_buffer_state(YY_CURRENT_BUFFER);
|
||||
(void) yy_scan_bytes(buf.c_str(), buf.size());
|
||||
yy_push_state(0);
|
||||
}
|
||||
|
||||
void
|
||||
flex_unset_buffer()
|
||||
{
|
||||
(void)&yy_top_state; // shut up a g++ warning.
|
||||
yy_pop_state();
|
||||
yypop_buffer_state();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2008, 2013 Laboratoire de Recherche et Développement
|
||||
// de l'Epita (LRDE).
|
||||
// Copyright (C) 2008, 2013, 2014 Laboratoire de Recherche et
|
||||
// Développement de l'Epita (LRDE).
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
//
|
||||
|
|
@ -35,7 +35,8 @@ namespace spot
|
|||
{
|
||||
int flex_open(const std::string& name);
|
||||
void flex_close();
|
||||
void flex_scan_string(const char* s);
|
||||
void flex_set_buffer(const std::string& buf);
|
||||
void flex_unset_buffer();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue