From 817a234ab73f987e8a7689be613e0150a9bd8029 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 27 May 2011 14:28:37 -0500 Subject: [PATCH] Reorder indexable checks to defer calling size --- lib/linguist/blob_helper.rb | 16 ++++++++-------- test/fixtures/blob/file.txt | 0 test/test_blob.rb | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 test/fixtures/blob/file.txt diff --git a/lib/linguist/blob_helper.rb b/lib/linguist/blob_helper.rb index d6bdcb10..f3cc74b0 100644 --- a/lib/linguist/blob_helper.rb +++ b/lib/linguist/blob_helper.rb @@ -216,18 +216,18 @@ module Linguist # # Return true or false def indexable? - if size > 100 * 1024 - false - elsif !text? - false - elsif generated? + if !text? false elsif ['.po', '.sql'].include?(pathname.extname) false - elsif Language.find_by_extension(pathname.extname) - true - else + elsif !Language.find_by_extension(pathname.extname) false + elsif generated? + false + elsif size > 100 * 1024 + false + else + true end end diff --git a/test/fixtures/blob/file.txt b/test/fixtures/blob/file.txt new file mode 100644 index 00000000..e69de29b diff --git a/test/test_blob.rb b/test/test_blob.rb index 6592ecd8..2acade03 100644 --- a/test/test_blob.rb +++ b/test/test_blob.rb @@ -172,7 +172,7 @@ class TestBlob < Test::Unit::TestCase def test_indexable assert blob("file.txt").indexable? - assert blob("file.rb").indexable? + assert blob("foo.rb").indexable? assert !blob("defun.kt").indexable? assert !blob("github.po").indexable? assert !blob("dump.sql").indexable?