Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/DataAccessProvider.java @ 606:5daa42067e7c
Avoid mmap files when only few bytes are to be read
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 07 May 2013 14:16:35 +0200 |
parents | ed243b668502 |
children | e1b29756f901 |
comparison
equal
deleted
inserted
replaced
605:c56edf42be64 | 606:5daa42067e7c |
---|---|
82 // ensure contract of CFG_PROPERTY_MAPIO_LIMIT, for mapioBoundary == 0 use MAX_VALUE so that no file is memmap-ed | 82 // ensure contract of CFG_PROPERTY_MAPIO_LIMIT, for mapioBoundary == 0 use MAX_VALUE so that no file is memmap-ed |
83 private static int mapioBoundaryValue(int mapioBoundary) { | 83 private static int mapioBoundaryValue(int mapioBoundary) { |
84 return mapioBoundary == 0 ? Integer.MAX_VALUE : mapioBoundary; | 84 return mapioBoundary == 0 ? Integer.MAX_VALUE : mapioBoundary; |
85 } | 85 } |
86 | 86 |
87 public DataAccess createReader(File f) { | 87 public DataAccess createReader(File f, boolean shortRead) { |
88 if (!f.exists()) { | 88 if (!f.exists()) { |
89 return new DataAccess(); | 89 return new DataAccess(); |
90 } | 90 } |
91 try { | 91 try { |
92 FileChannel fc = new FileInputStream(f).getChannel(); | 92 FileChannel fc = new FileInputStream(f).getChannel(); |
93 long flen = fc.size(); | 93 long flen = fc.size(); |
94 if (flen > mapioMagicBoundary) { | 94 if (!shortRead && flen > mapioMagicBoundary) { |
95 // TESTS: bufLen of 1024 was used to test MemMapFileAccess | 95 // TESTS: bufLen of 1024 was used to test MemMapFileAccess |
96 return new MemoryMapFileAccess(fc, flen, mapioBufSize, context.getLog()); | 96 return new MemoryMapFileAccess(fc, flen, mapioBufSize, context.getLog()); |
97 } else { | 97 } else { |
98 // XXX once implementation is more or less stable, | 98 // XXX once implementation is more or less stable, |
99 // may want to try ByteBuffer.allocateDirect() to see | 99 // may want to try ByteBuffer.allocateDirect() to see |