remove unnecessary cloning of SourcePosition, reduce SourcePosition size. clean, format

This commit is contained in:
2020-10-06 23:12:11 +02:00
parent 91573140a4
commit 33ec1461e4
39 changed files with 207 additions and 206 deletions
+14 -14
View File
@@ -8,9 +8,9 @@ addons:
- libelf-dev
- libdw-dev
rust:
- nightly
- nightly
os:
- linux
- linux
env:
global:
@@ -21,16 +21,16 @@ before_script:
- pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH
script:
- travis-cargo build
- travis-cargo test
- travis-cargo bench
- travis-cargo doc
- travis-cargo build
- travis-cargo test
- travis-cargo bench
- travis-cargo doc
after_success:
- |
[ $TRAVIS_BRANCH = master ] &&
[ $TRAVIS_PULL_REQUEST = false ] &&
echo '<meta http-equiv=refresh content=0;url=sexp/index.html>' > target/doc/index.html &&
git clone --depth 1 https://github.com/davisp/ghp-import &&
./ghp-import/ghp-import -n target/doc &&
git push -fq https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages
- travis-cargo coveralls --no-sudo
- |
[ $TRAVIS_BRANCH = master ] &&
[ $TRAVIS_PULL_REQUEST = false ] &&
echo '<meta http-equiv=refresh content=0;url=sexp/index.html>' > target/doc/index.html &&
git clone --depth 1 https://github.com/davisp/ghp-import &&
./ghp-import/ghp-import -n target/doc &&
git push -fq https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages
- travis-cargo coveralls --no-sudo
+3 -3
View File
@@ -4,12 +4,12 @@ version = "1.1.4"
authors = ["Clark Gaebel <cg.wowus.cg@gmail.com>"]
documentation = "https://cgaebel.github.io/sexp"
homepage = "https://github.com/cgaebel/sexp"
repository = "https://github.com/cgaebel/sexp"
homepage = "https://github.com/cgaebel/sexp"
repository = "https://github.com/cgaebel/sexp"
readme = "README.md"
keywords = [ "sexp", "parsing", "s-expression", "file-format" ]
keywords = ["sexp", "parsing", "s-expression", "file-format"]
description = "A small, simple, self-contained, s-expression parser and pretty-printer."
+7 -7
View File
@@ -12,11 +12,11 @@ pub struct Error {
#[derive(Debug, PartialEq, Clone, Default)]
pub struct SourcePosition {
/// The line number on which the error occurred.
pub line: usize,
pub line: u32,
/// The column number on which the error occurred.
pub column: usize,
pub column: u32,
/// The index in the given string which caused the error.
pub index: usize,
pub index: u32,
}
/// Since errors are the uncommon case, they're boxed. This keeps the size of
@@ -56,9 +56,9 @@ pub(crate) fn get_line_and_column(s: &str, pos: usize) -> SourcePosition {
}
}
SourcePosition {
line,
column: cmp::max(col, 0) as usize,
index: pos,
line: line as u32,
column: cmp::max(col, 0) as u32,
index: pos as u32,
}
}
@@ -66,7 +66,7 @@ pub(crate) fn get_line_and_column(s: &str, pos: usize) -> SourcePosition {
fn err_impl(message: &'static str, s: &str, pos: &usize) -> Err {
Box::new(Error {
message,
pos: get_line_and_column(s, *pos)
pos: get_line_and_column(s, *pos),
})
}
+1 -1
View File
@@ -11,9 +11,9 @@ use std::borrow::Cow;
use std::fmt;
use std::str::{self, FromStr};
use error::{ERes, err, spos};
pub use error::Error;
pub use error::SourcePosition;
use error::{ERes, err, spos};
#[cfg(test)]
mod test;
+3 -3
View File
@@ -27,8 +27,8 @@ fn test_pp() {
fn test_tight_parens() {
let s = "(hello(world))";
let sexp = parse(s).unwrap();
assert_eq!(sexp, Sexp::List(vec![Sexp::Atom(Atom::S("hello".into()), None),
Sexp::List(vec![Sexp::Atom(Atom::S("world".into()), None)], None)], None));
assert_eq!(sexp, Sexp::List(vec![Sexp::Atom(Atom::S("hello".into()), Default::default()),
Sexp::List(vec![Sexp::Atom(Atom::S("world".into()), Default::default())], Default::default())], Default::default()));
let s = "(this (has)tight(parens))";
let s2 = "( this ( has ) tight ( parens ) )";
assert_eq!(parse(s).unwrap(), parse(s2).unwrap());
@@ -66,5 +66,5 @@ fn line_and_col_test() {
fn sexp_size() {
// I just want to see when this changes, in the diff.
use std::mem;
assert_eq!(mem::size_of::<Sexp>(), mem::size_of::<isize>() * 5);
assert_eq!(mem::size_of::<Sexp>(), mem::size_of::<isize>() * 6);
}